# Catalan Number

  • Catalan numbers are a sequence of natural numbers that helps to solve many counting problem.
  • Terms starting with n=0 are : 1, 1, 2, 5, 14, 42, 132, 429, 1430 ….and so on

# Source Code - C++

#include <iostream>
using namespace std;

//Function to calculate Binomial Coefficient
int binomialC (int n, int k)
{
 int ans=1;
 if(k>n-k)
 k=n-k;

 for(int i=0; i<k; i++)
 {
  ans= ans*(n-i);
  ans= ans/(i+1);
 }
 return ans;
}

//Function to calculate Catalan Number = C(2n,n)/(n+1)
void catalan(int n)
{

 long int result, b;
 b=binomialC(2*n,n);
 result = b/(n+1);
 cout<<"Catalan Number is :"<<result;
}
//Main Function
int main()
{
 int n;
 cout<< "enter value of n \n";
 cin>>n;
 catalan(n);
 return 0;

}