Object

Write a program to draw a check-board and print it using if-else statement.

Algorithm

  1. Declare integer variables a and b.
  2. Read a and b.
  3. Repeat FOR b = 1 to b < 12
  4. Repeat FOR a = 1 to a < 12
    • IF (a+b)(mod 2) = 0, then
      • Write \xDB.
    • ELSE
      • Write one blank space.
    • [End of IF-ELSE structure.]
    • [End of inner FOR loop.]
      • Write new line.
    • [End of outer FOR loop.]
  5. Exit.

Flowchart

C++ Source Code

// program 43
#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)%2 == 0)	// even numbered rectangle
       cout << "\xDB";	// print filled rectangle
     else
       cout << " ";	// print blank rectangle
    }
    cout << endl;		// new line
  }
  return 0;
}

C Source Code

/*program 43*/
#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)%2 == 0)        /* even numbered rectangle */
	   printf("\xDB");	/* print filled rectangle */
	else
	   printf(" ");         /* print blank rectangle */
     printf("\n");              /* new line */
     }
  return 0;
}

Output

Design a site like this with WordPress.com
Get started