We read every piece of feedback, and take your input very seriously.
To see all available qualifiers, see our documentation.
There was an error while loading. Please reload this page.
1 parent b88d4e7 commit 41dede7Copy full SHA for 41dede7
misc/catalan.c
@@ -0,0 +1,28 @@
1
+/*
2
+code for computing nth catalan number
3
+*/
4
+#include<stdio.h>
5
+long int factorial(int x) //long int for more than 10 factorial
6
+{
7
+ int i;
8
+ long int fac; //fac stores x factorial
9
+ fac=x;
10
+ for(i=1;i<x;i++) //loop to calculate x factorial
11
+ {
12
+ fac=fac*(x-i);
13
+ }
14
+ return fac; //returning x factorial
15
+}
16
+int main()
17
18
+ long int f1,f2,f3; //long int for more than 10 factorial
19
+ int n;
20
+ float C; //C is catalan number for n;
21
+ scanf("%d",&n);
22
+ f1=factorial(2*n);
23
+ f2=factorial(n+1);
24
+ f3=factorial(n);
25
+ C=f1/(f2*f3); //formula for catalan number for n
26
+ printf("%0.2f",C);
27
+ return 0;
28
0 commit comments