/** @return Binomial coefficients with recursion, i.e. n choose k, C(n,k) or nCk. */
int CombinatorialRec(int n, int k)
{
/* We could do:
return factorial(n)/(factorial(n-k)*factorial(k));
But prefer the recursive approach instead, because it's not so prone
to numerical overflow. This approach uses the idea of the Pascal triangle. */
if (k <= 0 || k >= n)
return 1;
else
return CombinatorialRec(n-1,k-1) + CombinatorialRec(n-1,k);
}