Chapter 6:
Looping Structures
Programming Exercise
Problem # 52:
Write a program that generates the following checker board by using loop.
--------
--------
--------
--------
--------
--------
Solution:
#include<iostream>
#include<conio.h>
using namespace std;
int main()
{
int i, j;
for(i=1;i<=8;i++)
{
if(i%2!=0)
cout<<" ";
for(j=1;j<=8;j++)
cout<<"-";
cout<<endl;
}
}
#include<conio.h>
using namespace std;
int main()
{
int i, j;
for(i=1;i<=8;i++)
{
if(i%2!=0)
cout<<" ";
for(j=1;j<=8;j++)
cout<<"-";
cout<<endl;
}
}
Output:
Let me know in the comment section if you have any question.
Previous Post:
51. Program to display the following output using loop.
Comments
Post a Comment