Object
Write a program to draw a check-board and extend it using nested if-else statement.
Algorithm
- Declare integer variables a and b.
- Read a and b.
- Repeat FOR b = 1 to b < 12
- Repeat FOR a = 1 to a < 12
- IF a = b, then
- Write \xB2.
- ELSE IF (a+b)(mod 2) = 0, then
- Write \xDB.
- ELSE
- Write one blank space.
- [End of IF-ELSE-IF structure.]
- [End of inner FOR loop.]
- Write new line.
- [End of outer FOR loop.]
- IF a = b, then
- Exit.
Flowchart

C++ Source Code
// program 44
#include <iostream>
using namespace std;
int main()
{
int a, b;
for (b = 1; b < 12; b++) // stepping down
{
for (a = 1; a < 12; a++) // stepping right
{
if (a == b) // left top diagonal
cout << "\xB2"; // print grey
else if ((a + b) % 2 == 0)
cout << "\xDB"; // print filled rectangle
else
cout << " "; // print blank rectangle
}
cout << "\n"; // new line
}
return 0;
}
C Source Code
/*program 44*/
#include<stdio.h>
int main()
{
int a, b;
for(b=1; b<12; b++) /* stepping down */
{
for(a=1; a<12; a++) /* stepping right */
if(a==b) /* left top diagonal */
printf("\xB2"); /* print grey */
else if((a+b)%2==0)
printf("\xDB"); /* print filled rectangle */
else
printf(" "); /* print blank rectangle */
printf("\n"); /* new line */
}
return 0;
}
Output

