Asterisk's Inverted Triangle

My teacher gave me the logic for creating an inverted triangle..
I dont understand how the inner loop works. Kindly help?
*****
****
***
**
*

and the logic is :

1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
#include<iostream.h>
#include<conio.h>

void main()
{   int num;
cin>>num;
	 int i, j;
	 for(i = num; i>0; i--)
	 {
		  for(j = 1; j <= i; j++)
		  {
				cout<<"*";
		  }
		  cout<<"\n";
	 }
	 getch();
 }

What don't you understand exactly? Just try substituting numbers in it might make it easier for you.

The j loop is making sure that i number of stars are printed. Then when the loop exits, a newline is printed and the i loop reiterates, only i is decremented (so if it was 5 at first, it's now 4). The j loop does the same thing again, only now that i is 4 it'll output 4 stars before exiting the loop.
Topic archived. No new replies allowed.