6. Binomial coefficients

The following method simply uses the formula for calculating the binomial coefficient:

// Calculate the binomial coefficient.private long CalculatedNchooseK(int n, int k){    checked    {        return Factorial(n) / Factorial(k) / Factorial(n - k);    }}

This is quick and easy, but it only works if the factorials are all small enough to be calculated. For example, it is obvious that  because there's only one way to pick 100 items out of 100 items, namely picking all of them.

Unfortunately, to use the formula, the method must calculate 100!, and we know from the Solution to Problem 4. Factorials, that a program can only calculate factorials ...

Get The Modern C# Challenge now with the O’Reilly learning platform.

O’Reilly members experience books, live events, courses curated by job role, and more from O’Reilly and nearly 200 top publishers.