This code is suppose to return the binomial coefficient of two numbers. It works fine for smaller values but goes haywire with larger values. Is there something im overlooking?
1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18
int binomial(int n, int k)
{
int num, den ;
if ( n < k )
{
return(0) ;
}
else
{
den = 1;
num = 1 ;
for (int i = 1 ; i <= k ; i = i+1)
den = den * i;
for (int j = n-k+1; j<=n; j=j+1)
num = num * j;
return(num/den);
}
}