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:
- #include<iostream>
- using namespace std;
- int main()
- {
- for(int a=1;a<=10;a++)
- {
- cout<<"*";
- }
- cout<<endl;
- for(int b=1;b<=5;b++)
- {
- for(int c=1;c<=1;c++)
- {
- cout<<"*";
- }
- for(int d=1;d<=8;d++)
- {
- cout<<" ";
- }
- cout<<"*"<<endl;
- }
- for(int e=1;e<=10;e++)
- {
- cout<<"*";
- }
- return 0;
- }
Image View Of Code:(click image for large view)
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.
This comment has been removed by the author.
ReplyDelete//to print box
ReplyDelete#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();
}
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.
ReplyDeletei want like this?
#######
#*****#
#*##*#
#*##*#
#****#
######
THANKS YA!
ReplyDelete