Website Summary Files Commits Branches @commit @diff @stats
path: root / Sem. 03 / solutions / exercise 09 - rightmost pyramid.cpp
blob: 573b98bc1837acd2336f5045b85ea87bd393d0ce (plain) (blame)
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
32
33
34
35
36
#include <iostream>
using namespace std;

int main() 
{

    int n;
    cin >> n;

    // print the first part of the pyramid (the one going from 1 to n(n-1)...21)
    
    for(int i = 1; i <= n; i++) 
    {
        for(int k = n - i - 1; k >= 0; k--) 
            cout << " "; // print the spaces
        
        for(int j = i; j >= 1; j--) 
            cout << j; // print numbers j(j - 1)...21
        
        cout << endl;
    }
    // print the second part of the pyramid (the one going from (n-1)...21 to 1
    
    for(int i = n - 1; i >= 1; i--) 
    {
        for(int k = n - i - 1; k >= 0; k--) 
            cout << " ";
        
        for(int j = i; j >= 1; j--) 
            cout << j;
        
        cout << endl;
    }

    return 0;
}