-->





C++ Program to print box shape using for loop

Program Specifications:
  • Program uses for loops only to print box shape
  • Symbol used is asterisk (*)
  • Program prints fixed size box
  • To change the size change the values of for loops

    C++ Code:
    1. #include<iostream>
    2. using namespace std;
    3. int main()
    4. {
    5.      for(int a=1;a<=10;a++)
    6.         {
    7.             cout<<"*";
    8.         }
    9.             cout<<endl;
    10. for(int b=1;b<=5;b++)
    11.     {
    12.     for(int c=1;c<=1;c++)
    13.         {
    14.                 cout<<"*";
    15.         }
    16.         for(int d=1;d<=8;d++)
    17.               {
    18.                 cout<<" ";
    19.               }
    20.                 cout<<"*"<<endl;
    21.        }
    22. for(int e=1;e<=10;e++)
    23.  {
    24.  cout<<"*";
    25.  }
    26.  return 0;
    27. }

    Image View Of Code:(click image for large view)
    box shape using for loop c++ Programming
    C++ box shape using for loop c++ Programming
    box shape using for loop c++ Programming
    Sample Output:(Click on Image To View in Big Size)

     
     More Programs:
    
    C++ Shapes Programs
    
    C++ Simple Programs
    
    As in programming there are always more than one 
    ways to code try more than one ways to learn fast.
    

4 comments:

  1. This comment has been removed by the author.

    ReplyDelete
  2. //to print box
    #include
    #include
    #include
    main()
    {
    clrscr();
    int R1,C1,R2,C2;
    cout<<"Enter R1,C1,R2,C2:";
    cin>>R1>>C1>>R2>>C2; //INPUT
    gotoxy(R1,C1);cout<<(char)201;
    gotoxy(R1,C2);cout<<(char)200; //to print EDGES
    gotoxy(R2,C2);cout<<(char)188;
    gotoxy(R2,C1);cout<<(char)187;
    for(int i=R1+1;i<R2;i++)
    {
    delay(100);
    gotoxy(i,C1);cout<<(char)196; //to print VERTICAL LINE
    gotoxy(i,C2);cout<<(char)196;
    }
    for(int j=C1+1;j<C2;j++)
    {
    delay(100);
    gotoxy(R1,j);cout<<(char)179; //to print HORIZONTAL LINE
    gotoxy(R2,j);cout<<(char)179;
    }
    getch();
    }

    ReplyDelete
  3. Here is mine code of repeat only one time and inner all are of second pattern.but i want to repeat both two. like i want to draw outer box of (#) and inner is(*) and again they repeat after one another.
    i want like this?
    #######
    #*****#
    #*##*#
    #*##*#
    #****#
    ######

    ReplyDelete