I need help writing a function in c computer language. the function needs to be
ID: 3652017 • Letter: I
Question
I need help writing a function in c computer language.the function needs to be a loop function. Prints a Checkerboard shape of cross signs (X) of the given size.
A checkerboard has an alternate X and empty space. For example:
drawCheckerboard(8);
Here 8 means a checkerboard of 8 by 8
This displays the following output: (if it does not show up right on screen it is suppose to stagger the X and space with each new line so that it looks like a checker board)
X X X X
X X X X
X X X X
X X X X
X X X X
X X X X
X X X X
X X X X
So far this is what i have
#include<stdio.h>
#include<stdlib.h>
#include<math.h>
void drawCheckerboard(int size);
int main(void)
{
int size=0;
printf("Ener the size of the Checkerboard ");
scanf("%d", &size);
drawCheckerboard(size); $
return EXIT_SUCCESS;
}
void drawCheckerboard(int size)
{
int i, j, k;
k=0;
for(i = 0; i<size; i++)
{
for(j = 0; j<size; j++)
{
if(k==0)
{
printf("X");
k=1;
}
else
{
if(k==1)
{
printf(" ");
k=0;
}
}
}
printf(" ");
}
}
The problem with mine is that it does not shift my checker board displays like this
x x x x
x x x x
x x x x
x x x x
x x x x
x x x x
x x x x
x x x x
please help me stagger the X and spaces to look like checker board please