Wednesday, 30 October 2013

Catalan Numbers

In combinatorial mathematics, the Catalan numbers form a sequence of natural numbers that occur in various counting problems, often involving recursively defined objects. They are named after the Belgian mathematician Eugène Charles Catalan(1814–1894).

The nth Catalan number is given directly in terms of binomial coefficients by


The first Catalan numbers for n = 0, 1, 2, 3, … are
1, 1, 2, 5, 14, 42, 132, 429, 1430, 4862, 16796, 58786, 208012, 742900, 2674440, 9694845, 35357670, 129644790, 477638700, 1767263190, 6564120420, 24466267020, 91482563640, 343059613650, 1289904147324, 4861946401452, …


import java.util.Scanner;
class Catalan
{
public static void main(String[ ] args)
{
Scanner in=new Scanner (System.in);
System.out.println("Enter value of n(1...10):");
int n=in.nextInt();
long n1,n2,a;
long CatNumber;
int cnt=1;
if(n>=1 && n<=10)
{
for(a=1;a<=n;a++)
{
long factofa=1,factof2a=1;
for(long i=1;i<=a;i++)
factofa*=i;
for(long i=1;i<=2*a;i++)
factof2a*=i;
CatNumber=factof2a/((factofa*factofa)*(a+1));
System.out.println(" "+cnt++ +". "+CatNumber);
}
}
}
}

No comments:

Post a Comment