-
Notifications
You must be signed in to change notification settings - Fork 1
Expand file tree
/
Copy pathPattern27.cpp
More file actions
54 lines (45 loc) · 719 Bytes
/
Copy pathPattern27.cpp
File metadata and controls
54 lines (45 loc) · 719 Bytes
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
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
/*
1
1 1
1 2 1
1 3 3 1
1 4 6 4 1
1 5 10 10 5 1
1 6 15 20 15 6 1
*/
#include <iostream>
using namespace std;
// function to calculate nCr
int comb(int n, int r) // (5,3)
{
if (n == 0 || r == 0)
{
return 1;
}
int count = n;
for (int i = r - 1; i >= 1; i--) // 2
{
// denominator
r = r * i;
// numerator
count--;
n = n * count;
}
return n / r;
}
int main()
{
int n;
cout << "Enter the value of n: ";
cin >> n;
for (int i = 0; i < n; i++)
{
for (int j = 0; j <= i; j++)
{
cout << comb(i, j)<<" ";
}
cout << endl;
}
////cout << comb(5, 2);
return 0;
}