Advertisement
dim4o

Loops_07_CalculateCombinations

Mar 26th, 2014
637
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
C# 0.82 KB | None | 0 0
  1. static void Main()
  2.         {
  3.             int n = int.Parse(Console.ReadLine());
  4.             int k = int.Parse(Console.ReadLine());
  5.             if (1 < k && k < n && n < 100)
  6.             {
  7.                 int result1 = 1;
  8.                 int result2 = 1;
  9.                 int result;
  10.                 int count = 1;
  11.                 for (int index = n - k + 1; index <= n; index++)
  12.                 {
  13.                     result1 *= index;
  14.                     if (count <= k)
  15.                     {
  16.                         result2 *= count;
  17.                         count++;
  18.                     }
  19.                 }
  20.                 result = result1 / result2;
  21.                 Console.WriteLine(result);
  22.             }
  23.             else
  24.             {
  25.                 Console.WriteLine("out of range");
  26.             }
  27.         }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement