Venciity

[Jumpstart C#] loops demo - FactorialDoWhile

Jan 24th, 2014
156
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
C# 0.39 KB | None | 0 0
  1. using System;
  2. using System.Numerics;
  3.  
  4.  
  5. class Factorial
  6. {
  7.     static void Main()
  8.     {
  9.         Console.Write("n = ");
  10.         uint n = UInt32.Parse(Console.ReadLine());
  11.         uint originalN = n;
  12.         //decimal factorial = 1;
  13.         BigInteger factorial = 1;
  14.  
  15.         do
  16.         {
  17.             factorial *= n;
  18.             n--;
  19.         }
  20.         while (n > 1);
  21.        
  22.         Console.WriteLine("{0}! = {1}", originalN, factorial);
  23.     }
  24. }
Advertisement
Add Comment
Please, Sign In to add comment