In: Computer Science
This is for C++
You must use either a FOR, WHILE, or DO-WHILE loop in your solution for this problem. Write a quick main console program to output the following checker pattern to the console:
#_#_#_#_# _#_#_#_#_ #_#_#_#_# _#_#_#_#_ #_#_#_#_#
Code Screenshot :
Executable Code:
#include <iostream>
using namespace std;
int main()
{
//Declaring required variables
int i, j;
string b, w, t;
//Declaring the strings
b = "#";
w = "_";
//Required For loop
for (i = 1; i <= 5; i++)
{
for (j = 1; j <= 9; j++)
{
if (j % 2 !=
0)
{
//Printing the pattern
cout << b;
if (j < 10)
{
cout << "";
}
}
else if (j % 2
== 0)
{
cout << w;
if (j < 10)
{
cout << "";
}
}
}
t = b;
b = w;
w = t;
cout << endl;
}
}
Sample Output :
Please comment
below if you have any queries.
Please do give a thumbs up if you liked the answer thanks
:)