Advertisement
viraco4a

N_Choose_K_Count

Mar 28th, 2018
116
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
text 0.63 KB | None | 0 0
  1. using System;
  2. using System.Linq;
  3.  
  4. namespace NchooseKcount
  5. {
  6. class Program
  7. {
  8. static void Main()
  9. {
  10. int n = int.Parse(Console.ReadLine());
  11. int k = int.Parse(Console.ReadLine());
  12. decimal result = Binom(n, k);
  13. Console.WriteLine(result);
  14. }
  15.  
  16. private static decimal Binom(int n, int k)
  17. {
  18. if (k > n)
  19. {
  20. return 0;
  21. }
  22. if (k == 0 || k == n)
  23. {
  24. return 1;
  25. }
  26. return Binom(n - 1, k - 1) + Binom(n - 1, k);
  27. }
  28. }
  29. }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement