nKolchakoV

CalculateN!andK!

Nov 26th, 2013
87
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
C# 0.93 KB | None | 0 0
  1. using System;
  2. using System.Numerics;
  3. //Write a program that calculates N!*K! / (K-N)! for given N and K (1<N<K).
  4.  
  5. class Program
  6. {
  7. static void Main()
  8. {
  9.     Console.WriteLine("Please Enter N and K [1<N<K]");
  10.     Console.Write("Enter N = ");
  11.     int n = int.Parse(Console.ReadLine());
  12.     Console.Write("Enter K = ");
  13.     int k = int.Parse(Console.ReadLine());
  14.     BigInteger firstFact = 1;
  15.     BigInteger secondFact = 1;
  16.     BigInteger thirdFact = 1;
  17.     Console.Write("The result is: ");
  18.     if (n < k & 1 <= n)
  19.     {
  20.  
  21.         for (int i = 1; i <= n; i++)
  22.         {
  23.             firstFact *= i;
  24.         }
  25.         for (int q = 1; q <= k; q++)
  26.         {
  27.             secondFact *= q;
  28.         }
  29.         for (int y = 1; y <= (k - n); y++)
  30.         {
  31.             thirdFact *= y;
  32.         }
  33.         Console.Write("{0}\n ", (firstFact * secondFact) / thirdFact);
  34.     }
  35.     else
  36.         Console.WriteLine("Wrong input!");
  37. }
  38. }
Advertisement
Add Comment
Please, Sign In to add comment