need help shape

if user enetr 4 the output will be
----1
---2 2
--3 3 3
- 4 4 4 4

Last edited on
closed account (E3h7X9L8)
enjoy :)

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
30
31
#include <iostream>
using namespace std;

int main()
{

int n;
cout <<"Enter your number :"; cin >> n;

for(int i = 1; i <= n; i++)
{

  for(int j = 1; j <= n-i; j++)
 {
        cout << " ";
 }

  for(int j = 1; j <= i; j++)
 {
    cout << i ;
    if( i < 10 && n >= 10) // safe guard for input >= 10 so it can keep "tree form" output
        cout << "  ";
    else
        cout << " ";
 }

cout << endl;

}

}


Topic archived. No new replies allowed.