kirililchev3

Factorial

Jun 3rd, 2018
209
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
C# 0.68 KB | None | 0 0
  1. namespace Factorial
  2. {
  3.     using System;
  4.     using System.Numerics;
  5.  
  6.     public class Factorial
  7.     {
  8.         public static void Main(string[] args)
  9.         {
  10.             int number = int.Parse(Console.ReadLine());
  11.             Console.WriteLine(FactorialOfNumber(number));
  12.         }
  13.  
  14.         private static BigInteger FactorialOfNumber(int number)
  15.         {
  16.             if (number == 0)
  17.             {
  18.                 return 1;
  19.             }
  20.  
  21.             BigInteger factorial = number;
  22.             for (int i = number - 1; i > 1; i--)
  23.             {
  24.                 factorial = BigInteger.Multiply(factorial, i);
  25.             }
  26.  
  27.             return factorial;
  28.         }
  29.     }
  30. }
Advertisement
Add Comment
Please, Sign In to add comment