-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathBinomial.cpp
58 lines (52 loc) · 860 Bytes
/
Binomial.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
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
55
56
57
58
#include<iostream>
#include<stdlib.h>
using namespace std;
int c[100][100];
int min(int i,int k)
{
if(i<k)
return i;
else
return k;
}
void binomial(int n,int k)
{
for(int i=0;i<=n;i++)
{
for(int j=0;j<=min(i,k);j++)
{
if(j==0||j==i)
c[i][j] = 1;
else
c[i][j] = c[i-1][j-1] + c[i-1][j];
}
}
}
void Display(int n,int k)
{
for(int i=0;i<=n;i++)
{
for(int j=0;j<=min(i,k);j++)
{
cout << c[i][j] << " ";
if(j==min(i,k))
cout << endl;
}
}
}
int main()
{
cout << "Enter the n value : ";
int n,k;
cin >> n;
th : cout << "Enter the k value : ";
cin >> k;
if(k>n)
{
cout << "The value of K must and should lessthan or equal to value of N .." << endl;
goto th;
}
binomial(n,k);
Display(n,k);
return 0;
}