Program for nth Catalan Number |  ; A recursive function to find nth catalan number ; Base case ; catalan ( n ) is sum of catalan ( i ) * catalan ( n - i - 1 ) ; Driver code
#include <iostream> NEW_LINE using namespace std ; unsigned long int catalan ( unsigned int n ) { if ( n <= 1 ) return 1 ; unsigned long int res = 0 ; for ( int i = 0 ; i < n ; i ++ ) res += catalan ( i ) * catalan ( n - i - 1 ) ; return res ; } int main ( ) { for ( int i = 0 ; i < 10 ; i ++ ) cout << catalan ( i ) << " ▁ " ; return 0 ; }