Fenrir112

C# комбинаторика

Dec 4th, 2013
149
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
C# 0.58 KB | None | 0 0
  1.         static int fact(int i)
  2.         {
  3.             if (i > 1)
  4.                 return i * fact(i - 1);
  5.             else
  6.                 return 1;
  7.         }
  8.     static int permutation(int m, int n)
  9.         {
  10.             if (n > m)
  11.             {
  12.                 Console.WriteLine("Данные введены с ошибкой. Число гостей и число стульев поменяны местами");
  13.                 int t = n; n = m; m = t;
  14.             }
  15.             return fact(m) / (fact (n)*(fact (m-n)));
  16.  
  17.     Main()
  18.     {
  19.         Console.WriteLine(permutation(5, 2));
  20.     }
Advertisement
Add Comment
Please, Sign In to add comment