Skip to content

Commit deb750e

Browse files
Merge pull request ephremdeme#269 from khare-agraj/master
Pascal Triangle with Pretty Print
2 parents 37d470d + 5aed0ba commit deb750e

File tree

1 file changed

+36
-0
lines changed

1 file changed

+36
-0
lines changed
Lines changed: 36 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,36 @@
1+
2+
#include <iostream>
3+
4+
using namespace std;
5+
6+
void printPascal(int n) {
7+
for (int line = 1; line <= n; line++) {
8+
// used to represent C(line, i)
9+
int C = 1;
10+
11+
for (int i = 1; i < (n - line + 1); i++) {
12+
cout << " ";
13+
}
14+
15+
for (int i = 1; i <= line; i++) {
16+
// The first value in a line is always 1
17+
cout << C << " ";
18+
C = C * (line - i) / i;
19+
}
20+
21+
cout << "\n";
22+
}
23+
}
24+
25+
// Execution
26+
int main() {
27+
int n;
28+
29+
cout << "Please provide the number of rows of the triangle: ";
30+
31+
cin >> n;
32+
33+
printPascal(n);
34+
35+
return 0;
36+
}

0 commit comments

Comments
 (0)