Advertisement
AnitaN

06.LoopsHomework/06.CalculateExpression

Mar 29th, 2014
79
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
C# 0.80 KB | None | 0 0
  1. //Problem 6. Calculate N! / K!
  2. //Write a program that calculates n! / k! for given n and k (1 < k < n < 100).
  3. //Use only one loop.
  4.  
  5. using System;
  6. using System.Numerics;
  7. class CalculateExpression
  8. {
  9.     static BigInteger FactorialCalc(uint number)
  10.     {
  11.         BigInteger sum = 1;
  12.         for (int i = 1; i <= number; i++)
  13.         {
  14.             sum = sum * i;
  15.         }
  16.         return sum;
  17.     }
  18.  
  19.     static void Main()
  20.     {
  21.         Console.WriteLine("Calculate N!/K!");
  22.         Console.Write("Enter N:");
  23.         uint n = uint.Parse(Console.ReadLine());
  24.         Console.Write("Enter K:");
  25.         uint k = uint.Parse(Console.ReadLine());
  26.         BigInteger result = FactorialCalc(n) / FactorialCalc(k);
  27.         Console.Write("The Result is:{0}",result);
  28.         Console.WriteLine();
  29.     }
  30. }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement