Inverted pyramid help

so im suppose to make a inverted pyramid with 3 for loops with numbers going downward but i cant solve it. My brain is not working right. I have looked online for some examples but still cant figure it out. Any hints and tips is appreciated. I posted what I have so far.


1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
  #include<iostream>
using namespace std;
int main()
{
	int i = 1; int j = 1;
	int rows = 9;
	
	for (i = 1; i <= rows; i++)
	{
		for (j = 9; j <= 1; j--)
		{
			cout << "  ";
		}
		for (j = i; j > 1; --j)   // this for loop is right
		{
			cout << j;
			cout << "  ";
				
		}
		for (j = i; j < 9; ++j)
		{
			cout << j;
			cout << "  ";
		}

		cout << "\n";
	}

}
Last edited on
9 8 7 6 5 4 3 2 1 2 3 4 5 6 7 8 9
8 7 6 5 4 3 2 1 2 3 4 5 6 7 8
7 6 5 4 3 2 1 2 3 4 5 6 7

something like this but it wont let me formatted right
Topic archived. No new replies allowed.