Pyramid Numbers

Hello all,

one of my task is:
1.5 Modify the program so that the program will output the numbers below:

1 
12 
123 
1234 
12345 
123456 
1234567 
12345678 
123456789
 



currently, my coding is this:
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
#include <iostream>
using namespace std;

int main()
{
	int i;
	
	i = 1;
	while ( i <= 9 )
	{
		int j;
		j = 1;
		while ( j <= 9)
		{
		cout << j;
		j = j + 1;
		}
	cout << "\n";
	i = i + 1;
	
	}
	return 0;
}



and the output is:


123456789
123456789
123456789
123456789
123456789
123456789
123456789
123456789
123456789




what should I do to make it seems like the above?
Think about it.

The outer loop is responsible for the number of rows in the output.
The inner loop is responsible for the number of digits in each row.

Is the problem in the outer or in the inner loop?

How many times does the body of the inner loop execute?
How many times should the body of the inner loop execute?

The solution is very simple. You just have
to replace one character with another one.
Last edited on
This should be simple program :P

1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
void p(int x)
{
int i = 0;
while(i<x)
{
int j = 0;
while(j<i)
{
cout<<j;
j++;
}
i++;
cout<<endl;
}
}


didn't test it yet, might be errors.
Topic archived. No new replies allowed.