text: public static double NChooseK(int n, int k){double d = 1;if (n < 0 || k < 0 || n < k){d = double.NaN;}else{int minnk = Math.Min(n - k, k);int maxnk = Math.Max(n - k, k);for (int i = maxnk; i < n; i++){d *= i + 1;}d /= Factorial(minnk);}return d;}