svetlozar_kirkov

Calculate Factorial Method (Exercise)

Oct 3rd, 2014
239
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
C# 0.77 KB | None | 0 0
  1. using System;
  2. using System.Globalization;
  3. using System.Numerics;
  4. using System.Threading;
  5.  
  6. namespace ConsoleTests
  7. {
  8.     class ConsoleTests
  9.     {
  10.         static void Main()
  11.         {
  12.             Console.Write("Enter integer between 1 and 100: ");
  13.             CalcFact(int.Parse(Console.ReadLine()));
  14.             Console.ReadKey();
  15.         }
  16.  
  17.         private static void CalcFact(int input)
  18.         {
  19.             BigInteger fact = input;
  20.             for (int i = input - 1; i >= 2; i--)
  21.             {
  22.                 fact = fact * i;
  23.                 Thread.Sleep(200);
  24.                 Console.WriteLine("{0}", fact);
  25.                 Thread.Sleep(0);
  26.             }
  27.             Console.WriteLine("\nFactorial of {0} is: {1} ", input, fact);
  28.         }
  29.  
  30.     }
  31. }
Advertisement
Add Comment
Please, Sign In to add comment