Part of the series

Several example codes

~1 min read • Updated Oct 13, 2025

Program Overview

This Python program reads an integer n and computes the nᵗʰ Catalan number using the combinatorial formula:
Cₙ = (1 / (n + 1)) · comb(2n, n)


Python Code:


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}")

Sample Outputs:


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  

Written & researched by Dr. Shahin Siami