Advertisement
Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- //Write a program that calculates N!*K! / (K-N)! for given N and K (1<N<K).
- using System;
- using System.Numerics;
- class NKfactorialDividedKMinusNFactorial
- {
- static void Main()
- {
- Console.WriteLine("Please enter number n, which has to be integer bigger than 1:");
- int n = int.Parse(Console.ReadLine());
- Console.WriteLine("Please enter number k, which has to be integer bigger than n:");
- int k = int.Parse(Console.ReadLine());
- BigInteger productNFactorial = 1;
- if (n > 1 && k > n)//Checks input data.
- {
- for (int i = n; i > 1; i--)
- {
- productNFactorial = productNFactorial * i;//Calculates N!
- }
- BigInteger productKFactorialDividedKMunusNFactorial = 1;
- for (int i = k; i > (k - n); i--)// Calculates K! / (K-N)!, but omits the common parts.
- {
- productKFactorialDividedKMunusNFactorial = productKFactorialDividedKMunusNFactorial * i;
- }
- BigInteger finalResult = productKFactorialDividedKMunusNFactorial * productNFactorial;
- Console.WriteLine("The result is: {0}", finalResult);
- }
- else
- {
- Console.WriteLine("Wrong input!");
- }
- }
- }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement