Answer to Question #62350 in C# for Peter

Question #62350
Create the pattern of a chess board that is 8 x 8. Use X and O to represent the squares.

Create the appropriate nested looping structure to output the characters in an 8 x 8 grid on the screen using Console.Write() or Console.WriteLine() as appropriate.
Include a decision structure to ensure that alternate rows start with opposite characters as a real chess board alternates the colors among rows.
This is what your output should look like.

XOXOXOXO
OXOXOXOX
XOXOXOXO
OXOXOXOX
XOXOXOXO
OXOXOXOX
XOXOXOXO
OXOXOXOX


Used a nested loop
Used a decision structure to flip row output
Output is correct per above image
1
Expert's answer
2016-09-30T14:28:04-0400
using System;
using System.Collections.Generic;
using System.Text;
namespace Question_62350
{
class Program
{
static void Main(string[] args)
{
for (int i = 0; i < 8; i++)
{
for (int j=0; j < 8; j++)
if ((i + j) % 2 == 0) // a decision structure
// for switching first row character
Console.Write("X");
else
Console.Write("O");
Console.WriteLine();
}
Console.ReadKey();
}
}
}

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

LATEST TUTORIALS
APPROVED BY CLIENTS