There was an error while loading. Please reload this page.
1 parent e6863b9 commit 8c32cd0Copy full SHA for 8c32cd0
Algorithms/PascalTriangle
@@ -0,0 +1,41 @@
1
+// including necessary header files
2
+#include<bits/stdc++.h>
3
+using namespace std;
4
+
5
+// function to calculate binomial coefficient
6
+int BinCoef(int n, int k)
7
+{
8
+int result = 1;
9
+if (k > n - k)
10
11
+k = n - k;
12
+}
13
+for (int i = 0; i < k; i++)
14
15
+result *= (n - i);
16
+result /= (i + 1);
17
18
+return result;
19
20
21
+// function to generate Pascal triangle (of lines n)
22
+void pascal(int n)
23
24
+for (int i = 0; i < n; i++)
25
26
+for (int j = 0; j <= i; j++)
27
28
+cout << BinCoef(i, j)<<" ";
29
30
+cout << endl;
31
32
33
34
+// main function
35
+int main()
36
37
+int rows;
38
+cin >> rows;
39
+pascal(rows);
40
+return 0;
41
0 commit comments