mirror of
https://github.moeyy.xyz/https://github.com/TheAlgorithms/C.git
synced 2023-10-11 15:56:24 +08:00
Create catalan.c
This commit is contained in:
parent
b88d4e764b
commit
41dede7144
28
misc/catalan.c
Normal file
28
misc/catalan.c
Normal file
@ -0,0 +1,28 @@
|
|||||||
|
/*
|
||||||
|
code for computing nth catalan number
|
||||||
|
*/
|
||||||
|
#include<stdio.h>
|
||||||
|
long int factorial(int x) //long int for more than 10 factorial
|
||||||
|
{
|
||||||
|
int i;
|
||||||
|
long int fac; //fac stores x factorial
|
||||||
|
fac=x;
|
||||||
|
for(i=1;i<x;i++) //loop to calculate x factorial
|
||||||
|
{
|
||||||
|
fac=fac*(x-i);
|
||||||
|
}
|
||||||
|
return fac; //returning x factorial
|
||||||
|
}
|
||||||
|
int main()
|
||||||
|
{
|
||||||
|
long int f1,f2,f3; //long int for more than 10 factorial
|
||||||
|
int n;
|
||||||
|
float C; //C is catalan number for n;
|
||||||
|
scanf("%d",&n);
|
||||||
|
f1=factorial(2*n);
|
||||||
|
f2=factorial(n+1);
|
||||||
|
f3=factorial(n);
|
||||||
|
C=f1/(f2*f3); //formula for catalan number for n
|
||||||
|
printf("%0.2f",C);
|
||||||
|
return 0;
|
||||||
|
}
|
Loading…
Reference in New Issue
Block a user