Skip to content

Commit f411d68

Browse files
Merge pull request #799 from rak108/master
nth catalan number in C programming
2 parents 696b191 + 213e8e2 commit f411d68

File tree

1 file changed

+31
-0
lines changed

1 file changed

+31
-0
lines changed
Lines changed: 31 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,31 @@
1+
//nth catalan number
2+
3+
#include<stdio.h>
4+
5+
long long int cat(int n)
6+
{
7+
int i,j;
8+
long long int c[n + 1];
9+
10+
c[0]=c[1]=1;
11+
12+
for (i=2;i<=n;i++)
13+
{
14+
c[i]=0;
15+
for (j=0;j<i;j++)
16+
c[i]+=c[j]*c[i-j-1];
17+
}
18+
19+
20+
return c[n];
21+
}
22+
23+
void main()
24+
{
25+
int N;
26+
printf("\nEnter the value of n [nth catalan number]");
27+
scanf("%d",&N);
28+
printf("\n\n The nth catalan number is:\n");
29+
printf("%Ld \n",cat(N));
30+
31+
}

0 commit comments

Comments
 (0)