I have some problem about Nested Loop on C programming I tried to print the list like this:
| |0|1|2|3|4|5|6|7|8|9|
|0| | | | | | | | | | |
|1| | | | | | | | | | |
|2| | | | | | | | | | |
|3| | | | | | | | | | |
|4| | | | | | | | | | |
|5| | | | | | | | | | |
|6| | | | | | | | | | |
|7| | | | | | | | | | |
|8| | | | | | | | | | |
|9| | | | | | | | | | |
but there are something problem when i type my code and display:
| |0|1|2|3|4|5|6|7|8|9|
|0|0|0|0|0|0|0|0|0|0|0|
|1|0|1|1|1|1|1|1|1|1|1|
|2|0|2|2|2|2|2|2|2|2|2|
|3|0|3|3|3|3|3|3|3|3|3|
|4|0|4|4|4|4|4|4|4|4|4|
|5|0|5|5|5|5|5|5|5|5|5|
|6|0|6|6|6|6|6|6|6|6|6|
|7|0|7|7|7|7|7|7|7|7|7|
|8|0|8|8|8|8|8|8|8|8|8|
|9|0|9|9|9|9|9|9|9|9|9|
There is my code :
void displayBoard(Cell board[BOARD_HEIGHT][BOARD_WIDTH], Player * player)
{
int i, j;
printf("| ");
for (j = 0; j < BOARD_WIDTH; j++)
{
printf("|%d",j);
}
printf("|\n");
for (i = 0; i < BOARD_HEIGHT; i++)
{
for (j = 0; j < BOARD_WIDTH; j++)
{
printf("|%d",i);
if (j == 0)
{
printf("|%d",j);
}
}
printf("|\n");
}
printf("\n");
}
Have someone can help for this condition: only one row and one column, other is empty.
printf("|%d",i);inside the inner loop?printf("|%d",i); if (j == 0)-->if (j == 0) printf("|%d",i);Seems likeprintf("|%d",i)should be done outside thefor (j)loop.