There was an error while loading. Please reload this page.
2 parents 37d470d + 5aed0ba commit deb750eCopy full SHA for deb750e
Algorithms/Pascal/pascalTriangle.cpp
@@ -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