Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- using System;
- using System.Numerics;
- //Write a program that calculates N!*K! / (K-N)! for given N and K (1<N<K).
- class Program
- {
- static void Main()
- {
- Console.WriteLine("Please Enter N and K [1<N<K]");
- Console.Write("Enter N = ");
- int n = int.Parse(Console.ReadLine());
- Console.Write("Enter K = ");
- int k = int.Parse(Console.ReadLine());
- BigInteger firstFact = 1;
- BigInteger secondFact = 1;
- BigInteger thirdFact = 1;
- Console.Write("The result is: ");
- if (n < k & 1 <= n)
- {
- for (int i = 1; i <= n; i++)
- {
- firstFact *= i;
- }
- for (int q = 1; q <= k; q++)
- {
- secondFact *= q;
- }
- for (int y = 1; y <= (k - n); y++)
- {
- thirdFact *= y;
- }
- Console.Write("{0}\n ", (firstFact * secondFact) / thirdFact);
- }
- else
- Console.WriteLine("Wrong input!");
- }
- }
Advertisement
Add Comment
Please, Sign In to add comment