Advertisement
ivanov_ivan

Factorial

Aug 21st, 2016
127
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
C# 0.80 KB | None | 0 0
  1. using System;
  2. using System.Collections.Generic;
  3. using System.Linq;
  4. using System.Text;
  5. using System.Threading.Tasks;
  6.  
  7. namespace Factorial
  8. {
  9.     class Factorial
  10.     {
  11.         static void Main(string[] args)
  12.         {
  13.             int number = int.Parse(Console.ReadLine());
  14.             var factorial = number;
  15.  
  16.             for(int i = 1; i < number; i++)
  17.             {
  18.                 factorial = factorial * ( number - i );
  19.             }
  20.             Console.WriteLine(factorial);
  21.  
  22.             /* Second solution */
  23.             //var n = int.Parse(Console.ReadLine());
  24.             //var factorial = 1;
  25.             //do
  26.             //{
  27.             //    factorial = factorial * n;
  28.             //    n--;
  29.             //} while(n > 1);
  30.             //Console.WriteLine(factorial);
  31.         }
  32.     }
  33. }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement