06-05-2011, 03:50 PM
|
| Never Give Up | | Join Date: Jan 2011 Location: SahiwaL Age: 31
Posts: 26
Program / Discipline: BSIT Class Roll Number: 10-26 | |
A Program that prints square pattern stars in the output. #include <iostream.h> #include <conio.h> int main(void) { int i; int j; int side; clrscr(); cout<<"Enter side\n"; cin>>side; for(i=0;i<side;i++) { cout<<"*"; //print top row } for(j=0;j<side-2;j++) //side-2 to account for top and bottom rows { cout<<"\n"; cout<<"*"; //print left side for(i=0;i<(side-2);i++) //side-2 to account for left and right sides {
cout<<" "; //print spaces } cout<<"*"; //print right side } cout<<"\n"; for(i=0;i<(side);i++)
{ cout<<"*"; //print bottom row } getch();
} |