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! for given N and K (1<K<N).
- class Program
- {
- static void Main()
- {
- Console.Write("Enter a number for factorial !N [N > K > 1]: ");
- int n = int.Parse(Console.ReadLine());
- Console.Write("Enter a number for factorial !K: ");
- int k = int.Parse(Console.ReadLine());
- BigInteger sumK = 1;
- BigInteger sumN = 1;
- if (n > k & n >= 0)
- {
- Console.Write("!{0}", n);
- while (n >= 1)
- {
- sumN *= n;
- n--;
- }
- Console.WriteLine(" = {1}", n, sumN);
- Console.Write("!{0}", k);
- while (k >= 1)
- {
- sumK *= k;
- k--;
- }
- Console.WriteLine(" = {1}", k, sumK);
- Console.WriteLine("[!N/!K]: {0}/{1} = {2}", sumN, sumK, sumN / sumK);
- }
- else
- {
- Console.WriteLine("Invalid Input !");
- }
- }
- }
Advertisement
Add Comment
Please, Sign In to add comment