Answer to Question #201444 in C++ for shuvo

Question #201444

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


1
Expert's answer
2021-06-01T05:14:29-0400
#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;
}

Need a fast expert's response?

Submit order

and get a quick answer at the best price

for any assignment or question with DETAILED EXPLANATIONS!

Comments

No comments. Be the first!

Leave a comment