Print a checker board (8-by-8 grid). Each square should be 5 -by-3
characters wide. A 2-by-2 example is as follows:(if you take 5 by 3 characters wide, then only you will get square.)
Program for 8by8 checker board:
#include<stdio.h>
int main()
{
char c[33][49]; /* cheker_board array */
int i,j,k; /* loop variables */
for(i=0;i<33;i++) /* initializing all elements to white space */
for(j=0;j<49;j++)
c[i][j]=32;
int temp;
for(k=1;k<32;k++) /* storing columns(unwanted elements will be
replaced when rows are stored) */
{
for(j=0;j<49;j=j+6)
{
c[k][j]='|';
}
}
for(i=0;i<33;i=i+4) /* storing rows */
{
j=0; c[i][j]='+';
for(k=0;k<8;k++)
{
temp=j;
for(j=(temp+1);j<=(temp+5);j++)
{
c[i][j]='-';
}
c[i][j]='+';
}
}
for(i=0;i<33;i++){ /* print the 2-D array */
for(j=0;j<49;j++)
printf("%c",c[i][j]);
printf("\n");
}
return 0;
}
Output: