Skip to content

Commit

Permalink
Merge pull request rathoresrikant#757 from osoba/catalan-python
Browse files Browse the repository at this point in the history
added catalan number algorithm in python without using the factorial function
  • Loading branch information
rathoresrikant authored Sep 30, 2019
2 parents 9237979 + e20a2d4 commit 633aa8a
Showing 1 changed file with 17 additions and 0 deletions.
17 changes: 17 additions & 0 deletions Algorithms/Mathematical Algorithms/catalan_without_factorial.py
Original file line number Diff line number Diff line change
@@ -0,0 +1,17 @@
'''Python program to find the nth catalan number without using the computationally intensive factorial function'''

number = int(input('Enter a number: '))



def catalan(n):
if n <= 1: return 1

numerator, denominator = 1, 1

for i in range(2, n+1):
numerator *= (n+i)
denominator *= i
return int(numerator/denominator)

print( catalan(number) )

0 comments on commit 633aa8a

Please sign in to comment.