/*Catalan Numbers are the numbers of the form:
(2n)!/((n!)^2*(n+1))*/
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);
}
}
}
}
(2n)!/((n!)^2*(n+1))*/
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