This Python program reads an integer n and computes the nᵗʰ Catalan number using the combinatorial formula:
Cₙ = (1 / (n + 1)) · comb(2n, n)
import math
def catalan_number(n: int) -> int:
return math.comb(2 * n, n) // (n + 1)
# Read input from user
n = int(input("Enter value for n: "))
result = catalan_number(n)
print(f"The {n}ᵗʰ Catalan number is: {result}")
Input: n = 0 → Output: 1
Input: n = 1 → Output: 1
Input: n = 2 → Output: 2
Input: n = 3 → Output: 5
Input: n = 4 → Output: 14
Input: n = 5 → Output: 42