-
nested for loops/
Code:
#include<iostream>
#include<conio.h>
#include<iomanip>
using std::cout;
using std::cin;
using std::endl;
using std::setw;
int main()
{
// declare & initialize variable/s
int x,y,z,c;
// print astericks
for(x=1;x<=11;x++)
{
cout<<'*';
for(y=x-1;y<=9;y++)
cout<<'*';cout<<endl;
}
cout<<"\n";
for(x=0;x<=11;x++)
{
cout<<'*';
for(y-=x;y<=9;y++)
cout<<'*';cout<<endl;
}
cout<<"\n";
for(x=1;x<=11;x++)
{
cout<<'*';
for(y=1;y<=9;y++)
cout<<'*';cout<<endl;cout<<setw(2);
}
getch();
}
The last for loop doesn't work if I have to print the following
*********
********
*******
******
*****
****
***
**
*
should it be
( print one whole row of * and print the next row after leaving first *)?
-
Something like this ?
Code:
for(int x = 9; x > 0; x--)
{
for(int y = 0; y < x; y++)
{
cout << '*';
}
cout << endl;
}
Just a small remark:
In your comments you say "declare & initialize variable/s", when no initialization is done.
-
u r right/
Thanku Calthun.I got it.And yes I didn't initialize the variables.Got to keep that in mind in future.:cool: