NESTED LOOPS

I need help on writing this
**********
*********
********
*******
******
*****
****
***
**
*
I figured how to do it the other way going down
with this
int main ()
{
for (row=1; row <=10 ; row++)
{
for (col=1; row>=col; col++)
{
cout << "*" ;
}
cout << endl ;
}
}
please help, thank you :)
1) You should use code tags
[code]//stuff[/code]
looks like: //stuff it makes it easier to read.

2) You should learn to start with 0 and not 1 in for loops since many times when you index they begin with index 0 and not 1 like in arrays and stl containers.

3) All you have to do is reverse your code and start from the 10th row down to the first like this

1
2
3
4
5
6
7
8
9
10
const int ROWS = 10;

for( int row = ROWS; row > 0; --row )
{
    for( int column = 0; column < row; ++column )
    {
        std::cout << '*';
    }
    std::cout << std::endl;
}


4) Try not to use magic numbers line you have in your first for loop "10" what is 10? It is the max rows. So you should declare it as a constant value.

http://ideone.com/MVwbFl

Topic archived. No new replies allowed.