Advertisement
Fundamentalen

CalculateNFactDividedToKFact

Mar 23rd, 2014
1,033
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
C# 0.82 KB | None | 0 0
  1. using System;
  2. using System.Numerics;
  3.  
  4. class CalculateNFactDividedToKFact
  5. {
  6.     static void Main()
  7.     {
  8.         Console.Write("n = ");
  9.         int n = int.Parse(Console.ReadLine());
  10.         Console.Write("k = ");
  11.         int k = int.Parse(Console.ReadLine());
  12.  
  13.         if (n > 1 && k > 1 && n < 100 && k < 100)
  14.         {
  15.             BigInteger factN = 1;
  16.             BigInteger factK = 1;
  17.             BigInteger result = 0;
  18.  
  19.             for (int i = 1; i <= n; i++)
  20.             {
  21.                 factN *= i;
  22.             }
  23.  
  24.             for (int j = 1; j <= k; j++)
  25.             {
  26.                 factK *= j;
  27.             }
  28.  
  29.             result = factN / factK;
  30.  
  31.             Console.WriteLine(result);
  32.         }
  33.         else
  34.         {
  35.             Console.WriteLine("Invalid input!");
  36.         }
  37.     }
  38. }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement