Advertisement
stanevplamen

FactorialExample

May 2nd, 2013
57
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
C# 0.75 KB | None | 0 0
  1. using System;
  2. using System.Numerics;
  3.  
  4.  
  5. class PrimeCheck
  6. {
  7.     static void Main()
  8.     {
  9.         DateTime startTime = DateTime.Now;
  10.         Console.Write("n = ");
  11.         int n = Convert.ToInt32(Console.ReadLine());
  12.         // Calculate n! =
  13.         BigInteger result = 1;
  14.         while (true)
  15.         {
  16.             Console.Write(n);
  17.             if (n==1)
  18.             {
  19.                 break; // kato stignem do 1 se mahame ot cikula
  20.             }
  21.             Console.Write(" * ");
  22.             checked
  23.             {
  24.                 result = result * n;
  25.             }
  26.             n--;
  27.         }
  28.         Console.WriteLine(" = {0}", result);
  29.         DateTime finishtTime = DateTime.Now;
  30.         Console.WriteLine(finishtTime-startTime);
  31.     }
  32. }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement