(Checkerboard Pattern of Asterisks) Write a program that displays the following checkerboard pattern. Your program must use only three output statements, one of each of the following forms:
cout << "* ";
cout << ' ' ;
cout << endl;
* * * * * * * *
* * * * * * * *
* * * * * * * *
* * * * * * * *
* * * * * * * *
* * * * * * * *
* * * * * * * *
* * * * * * * *
#include
#include
using namespace std;
int main()
{
int column;
int row = 1;
while( row <= 8 ) {
column = 1;
while(column <= 16) {
if( ((column % 2 == 0) & & (row % 2 == 0) ) | | ((column % 2 == 1) & & (row % 2 == 1) ) ) {
cout << "*";
column++;
}
else
{
cout << " ";
column++;
}
}c
out << endl;
row++;
}/
/for pause
system("PAUSE") ;
return 0;
}
cout << "* ";
cout << ' ' ;
cout << endl;
* * * * * * * *
* * * * * * * *
* * * * * * * *
* * * * * * * *
* * * * * * * *
* * * * * * * *
* * * * * * * *
* * * * * * * *
Solution:
#include<iostream>#include
#include
using namespace std;
int main()
{
int column;
int row = 1;
while( row <= 8 ) {
column = 1;
while(column <= 16) {
if( ((column % 2 == 0) & & (row % 2 == 0) ) | | ((column % 2 == 1) & & (row % 2 == 1) ) ) {
cout << "*";
column++;
}
else
{
cout << " ";
column++;
}
}c
out << endl;
row++;
}/
/for pause
system("PAUSE") ;
return 0;
}
Post A Comment:
0 comments: