Skip to content

Commit 5cdb85d

Browse files
committed
Added binomial coefficient
1 parent a61b05b commit 5cdb85d

File tree

1 file changed

+28
-0
lines changed

1 file changed

+28
-0
lines changed

maths/binomial_coefficient.py

Lines changed: 28 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,28 @@
1+
# Python program to find binomial coefficient using pascals triangle.
2+
3+
def solve(n,r):
4+
5+
6+
C = [0 for i in range(r+1)]
7+
8+
# nc0 = 1
9+
C[0] = 1
10+
11+
for i in range(1,n+1):
12+
13+
#to compute current row from previous row.
14+
j = min(i ,r)
15+
16+
while (j > 0):
17+
C[j] = C[j] + C[j-1]
18+
j -= 1
19+
20+
return C[r]
21+
22+
#sample Data
23+
n = 10
24+
r = 5
25+
26+
print (solve(n,r))
27+
28+

0 commit comments

Comments
 (0)