Skip to content
Open
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
7 changes: 7 additions & 0 deletions math/catalan.c
Original file line number Diff line number Diff line change
Expand Up @@ -6,6 +6,8 @@ long int factorial(int x) // long int for more than 10 factorial
{
int i;
long int fac; // fac stores x factorial
if (x == 0)
return 1; // 0! = 1: without this factorial(0) = 0 and the formula divides by zero
fac = x;
for (i = 1; i < x; i++) // loop to calculate x factorial
{
Expand All @@ -19,6 +21,11 @@ int main()
int n;
float C; // C is catalan number for n;
scanf("%d", &n);
if (n < 0 || n > 10)
{
printf("n must be in [0, 10]: (2n)! overflows long int beyond that\n");
return 1;
}
f1 = factorial(2 * n);
f2 = factorial(n + 1);
f3 = factorial(n);
Expand Down
Loading