-
Notifications
You must be signed in to change notification settings - Fork 687
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Merge pull request #799 from rak108/master
nth catalan number in C programming
- Loading branch information
Showing
1 changed file
with
31 additions
and
0 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
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)); | ||
|
||
} |