Advertisement
Martichka

Loops/Task 4 - Factorial divide

Dec 9th, 2012
80
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
C# 0.84 KB | None | 0 0
  1. using System;
  2. class FactorialDivision
  3. {
  4.     static void Main()
  5.     {
  6.         Console.WriteLine("Enter two numbers:");
  7.         Console.Write("N!");
  8.         int n = int.Parse(Console.ReadLine());
  9.         Console.Write("K!");
  10.         int k = int.Parse(Console.ReadLine());
  11.         decimal factorialN = 1;
  12.         decimal factorialK = 1;
  13.         if ((n < 1) || (k < 1) || (n < k))
  14.         {
  15.             Console.WriteLine("You made wrong input!");
  16.         }
  17.         else
  18.         {
  19.             do
  20.             {
  21.                 factorialN *= n;
  22.                 n--;
  23.             }
  24.             while (n > 0);
  25.             do
  26.             {
  27.                 factorialK *= k;
  28.                 k--;
  29.             }
  30.             while (k > 0);
  31.             Console.WriteLine("N! / K! = {0}", factorialN / factorialK);
  32.         }
  33.        
  34.     }
  35. }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement