Write a program that prints a simple chessboard.
Input format:
The first line contains the number of inputs T. The lines after that contain a different values for size of the chessboard
Output format:
Print a chessboard of dimensions size * size. Print a Print W for white spaces and B for black spaces.
Input:
2 3 5
Output:
WBW
BWB
WBW
WBWBW
BWBWB
WBWBW
BWBWB
WBWBW
Source Code:
#include<stdio.h>
int main()
{
int n;
scanf("%d",&n);
while(n){
int b;
scanf("%d",&b);
for(int i =0;i<b;i++){
for(int j=0;j<b;j++){
if((i+j)%2 == 0){
printf("W");
}else{
printf("B");
}
}
printf("\n");
}
n--;
}
return 0;
}
Output:
Input format:
The first line contains the number of inputs T. The lines after that contain a different values for size of the chessboard
Output format:
Print a chessboard of dimensions size * size. Print a Print W for white spaces and B for black spaces.
Input:
2 3 5
Output:
WBW
BWB
WBW
WBWBW
BWBWB
WBWBW
BWBWB
WBWBW
Source Code:
#include<stdio.h>
int main()
{
int n;
scanf("%d",&n);
while(n){
int b;
scanf("%d",&b);
for(int i =0;i<b;i++){
for(int j=0;j<b;j++){
if((i+j)%2 == 0){
printf("W");
}else{
printf("B");
}
}
printf("\n");
}
n--;
}
return 0;
}
Output:
2 3 5
WBW
BWB
WBW
WBWBW
BWBWB
WBWBW
BWBWB
WBWBW
No comments:
Post a Comment