Skip to content

Commit

Permalink
Merge pull request #799 from rak108/master
Browse files Browse the repository at this point in the history
nth catalan number in C programming
  • Loading branch information
rathoresrikant authored Oct 18, 2019
2 parents 696b191 + 213e8e2 commit f411d68
Showing 1 changed file with 31 additions and 0 deletions.
31 changes: 31 additions & 0 deletions Algorithms/DynamicProgramming/catalan_rakshita.c
Original file line number Diff line number Diff line change
@@ -0,0 +1,31 @@
//nth catalan number

#include<stdio.h>

long long int cat(int n)
{
int i,j;
long long int c[n + 1];

c[0]=c[1]=1;

for (i=2;i<=n;i++)
{
c[i]=0;
for (j=0;j<i;j++)
c[i]+=c[j]*c[i-j-1];
}


return c[n];
}

void main()
{
int N;
printf("\nEnter the value of n [nth catalan number]");
scanf("%d",&N);
printf("\n\n The nth catalan number is:\n");
printf("%Ld \n",cat(N));

}

0 comments on commit f411d68

Please sign in to comment.