Consider an 8 x 8 array for a board game: int board[8][8]; Using two nested loops, initialize the board so that 0s, and 1s alternate as on a checker board.
0 1 0 1 0 1 0 1
1 0 1 0 1 0 1 0
0 1 0 1 0 1 0 1
1 0 1 0 1 0 1 0
0 1 0 1 0 1 0 1
1 0 1 0 1 0 1 0
0 1 0 1 0 1 0 1
1 0 1 0 1 0 1 0
#include <iostream>
using namespace std;
int main()
{
int a[8][8];
for (int i = 0; i < 8; i++)
{
for (int j = 0; j < 8; j++)
{
if ((i + j) % 2 == 0) a[i][j] = 0;
else a[i][j] = 1;
cout << a[i][j];
}
cout << endl;
}
system("pause");
return 0;
}
Comments
Leave a comment