Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- //Write a program that calculates N!/K! for given N and K (1<K<N).
- using System;
- using System.Numerics;
- class NKfactorial
- {
- static void Main()
- {
- Console.WriteLine("Please enter number k, which has to be integer bigger than 1:");
- int k = int.Parse(Console.ReadLine());
- Console.WriteLine("Please enter number n, which has to be integer bigger than k:");
- int n = int.Parse(Console.ReadLine());
- BigInteger productNKFactorial = 1;
- if (k > 1 && n > k)//Checks whether input is correct.
- {
- for (int i = n; i > k; i--)
- //I do not calculate separately N! and K!, because K!
- //is contained in N! and therefore the common parts are not needed to be calculated.
- {
- productNKFactorial = productNKFactorial * i;
- }
- Console.WriteLine("The result is: {0}", productNKFactorial);
- }
- else
- {
- Console.WriteLine("Wrong input!");
- }
- }
- }
Advertisement
Add Comment
Please, Sign In to add comment