Navigation Menu

Currently the navigation bar is not functioning. Use the Blog Archive or the Google Custom Search to find content.

Wednesday, 26 June 2013

C++ program to print a checkboard (8-by-8 grid)

Print a checkboard (8-by-8 grid). Each square should be 5-by-2 characters wide. A 2-by-2 example follows:
+-----+-----+
|     |     |
|     |     |
+-----+-----+
|     |     |
|     |     |
+-----+-----+
Code :
#include <iostream.h>
#include <conio.h>
void main()
{
    int i,j,k,l;
    clrscr();
    for(i=0;i<9;i++)
    {
        for(j=0;j<8;j++)
        {
            cout<<"+";
            for(k=0;k<5;k++)
            {
                cout<<"-";
            }
        }
        cout<<"+"<<endl;
        if(i<8)
        {
            for(l=0;l<2;l++)
            {
                for(j=0;j<9;j++)
                {
                    for(k=0;k<2;k++)
                    {
                        if(k%5==0)
                            cout<<"|     ";
                    }
                }
                cout<<endl;
            }
        }
    }
    getch();
}
Output :
+-----+-----+-----+-----+-----+-----+-----+-----+
|     |     |     |     |     |     |     |     |
|     |     |     |     |     |     |     |     |
+-----+-----+-----+-----+-----+-----+-----+-----+
|     |     |     |     |     |     |     |     |
|     |     |     |     |     |     |     |     |
+-----+-----+-----+-----+-----+-----+-----+-----+
|     |     |     |     |     |     |     |     |
|     |     |     |     |     |     |     |     |
+-----+-----+-----+-----+-----+-----+-----+-----+
|     |     |     |     |     |     |     |     |
|     |     |     |     |     |     |     |     |
+-----+-----+-----+-----+-----+-----+-----+-----+
|     |     |     |     |     |     |     |     |
|     |     |     |     |     |     |     |     |
+-----+-----+-----+-----+-----+-----+-----+-----+
|     |     |     |     |     |     |     |     |
|     |     |     |     |     |     |     |     |
+-----+-----+-----+-----+-----+-----+-----+-----+
|     |     |     |     |     |     |     |     |
|     |     |     |     |     |     |     |     |
+-----+-----+-----+-----+-----+-----+-----+-----+
|     |     |     |     |     |     |     |     |
|     |     |     |     |     |     |     |     |
+-----+-----+-----+-----+-----+-----+-----+-----+

Note : The program above has been tested using TurboCPP. Leave a comment if you feel the program is incorrect and/or has errors and/or if the program and its output don't match. Please report about broken links.

No comments:

Post a Comment