Created
August 20, 2018 17:27
-
-
Save paramsingh/da9f3af15f92233a07e907cb8b89c723 to your computer and use it in GitHub Desktop.
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
# A recursive function to find nth catalan number | |
def catalan(n): | |
# Base Case | |
if n <=1 : | |
return 1 | |
# Catalan(n) is the sum of catalan(i)*catalan(n-i-1) | |
res = 0 | |
for i in range(n): | |
res += catalan(i) * catalan(n-i-1) | |
return res | |
t = int(input()) | |
for i in range(t): | |
x = int(input()) | |
print(catalan(x)) |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment