nKolchakoV

Untitled

Nov 24th, 2013
63
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! for given N and K (1<K<N).
  4.  
  5. class Program
  6. {
  7. static void Main()
  8. {
  9.     Console.Write("Enter a number for factorial !N [N > K > 1]: ");
  10.     int n = int.Parse(Console.ReadLine());
  11.     Console.Write("Enter a number for factorial !K: ");
  12.     int k = int.Parse(Console.ReadLine());
  13.     BigInteger sumK = 1;
  14.     BigInteger sumN = 1;
  15.     if (n > k & n >= 0)
  16.     {
  17.         Console.Write("!{0}", n);
  18.         while (n >= 1)
  19.         {
  20.             sumN *= n;
  21.             n--;
  22.  
  23.         }
  24.         Console.WriteLine(" = {1}", n, sumN);
  25.         Console.Write("!{0}", k);
  26.  
  27.         while (k >= 1)
  28.         {
  29.             sumK *= k;
  30.             k--;
  31.  
  32.         }
  33.         Console.WriteLine(" = {1}", k, sumK);
  34.         Console.WriteLine("[!N/!K]: {0}/{1} = {2}", sumN, sumK, sumN / sumK);
  35.     }
  36.     else
  37.     {
  38.         Console.WriteLine("Invalid Input !");
  39.     }
  40. }
  41. }
Advertisement
Add Comment
Please, Sign In to add comment