Help: Pyramid Nested Loop Pattern is inverted

The output that I need is this:
----------------------------------------------------
1
2
3
4
5
6
Enter Preferred Number: (any number from 0-9)(ex. 5)
    1
   1_2
  1_2_3
 1_2_3_4
1_2_3_4_5

...and so on...

But I had this other output instead:
----------------------------------------------------
1
2
3
4
5
6
Enter Preferred Number: (any number from 0-9)(ex. 5)
    5_
   4_5_
  3_4_5_
 2_3_4_5_
1_2_3_4_5_

...and so on...

How can I reverse the numbering and remove the underscore after the side of the pyramid, to match the example above? I don't know what the problem is. Please help me...

By the way, the program that I am using is Turbo C++...even though obsolete, but I still keep using it...XD

Here is the code that I made for the second example:
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
#include "conio.h"
#include "iostream.h"

int main()
{
	textcolor(LIGHTGREEN);
	clrscr();
  	int i,j,num;
	cout<<"Enter Preferred Number: ";
	cin>>num;
	clrscr();
	for (i=1;i<=num;i++)
	{
		for (j=num;j>i;j--)
		cout<<" ";
		for (int k=num-i+1;k<=num;k++)
		{
			cout<<k<<"_";
		}
		cout<<endl;
	}
	getch();
    return 0;
}
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
#include "conio.h"
#include "iostream.h"

int main()
{
	textcolor(LIGHTGREEN);
	clrscr();
  	int i,j,num;
	cout<<"Enter Preferred Number: ";
	cin>>num;
	clrscr();
	for (i=1;i<=num;i++)
	{
		for (j=num;j>i;j--)
		cout<<" ";
		for (int k=1; k<=i;k++)
		{
			cout<<k;
			if(k<j)
			{
				cout << "_";
			}
		}
		cout<<endl;
	}
	getch();
    return 0;
}

Just modified a bit, what do you say?
Last edited on
Just for fun:
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
#include <iostream>

using namespace std;

int main()
{
	int num = 0;
	int curr = 0;
	cout<<"Enter Preferred Number: ";
	cin >> num;
	do
	{
		int med = (num - curr); 
		for (int i = 1; i < med; ++i)
		{
			cout << " ";
		}
		
		for (int i = 0; i < curr; ++i)
		{
			cout << i + 1 << "_";
		}
		
		cout << ++curr << endl;
	} while (curr < num);
	
	return 0;
}
thanks for the help guys....really appreciated it! =)
Topic archived. No new replies allowed.