Venciity

[Jumpstart C#] loops demo - FactorialBreak

Jan 24th, 2014
164
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
C# 0.59 KB | None | 0 0
  1. using System;
  2.  
  3. class Factorial
  4. {
  5.     static void Main()
  6.     {
  7.         Console.Write("n = ");
  8.         uint n = UInt32.Parse(Console.ReadLine());
  9.  
  10.         Console.Write("{0}! = ", n);
  11.  
  12.         // "decimal" is the biggest integer type
  13.         decimal factorial = 1;
  14.  
  15.         // Perform an infinite loop
  16.         while (true)
  17.         {
  18.             Console.Write(n);
  19.             if (n == 1)
  20.             {
  21.                 break;
  22.             }
  23.             Console.Write(" * ");
  24.             factorial *= n;
  25.             n--;
  26.         }
  27.         Console.WriteLine(" = {0}", factorial);
  28.     }
  29. }
Advertisement
Add Comment
Please, Sign In to add comment