CPP
cpp
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 <iostream>
using namespace std;
// beta: triangle is right with numbert from 1 to 9, for numbers > 10 it's not optimized yet...
int lim, c = 0;
int main()
{
cin >> lim;
cout << "size of triangle: " << lim << endl << endl;
for (int i=1; i <= lim; i++){
for (int k = 0; k <= (lim - i); k++) {
cout << " ";
}
for (int l = 1; l <= i; l++) {
cout << l <<" ";
c += l;
}
cout << endl;
}
cout << endl << "sum of numbers in triangle is " << c;
return 0;
}
Enter to Rename, Shift+Enter to Preview
OUTPUT
Run