Advertisement
Guest User

Untitled

a guest
Jun 25th, 2018
165
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
C# 0.72 KB | None | 0 0
  1. using System;
  2. using System.Collections.Generic;
  3. using System.IO;
  4. using System.Numerics;
  5.  
  6. class Solution {
  7.     static void Main(String[] args) {
  8.         /* Enter your code here. Read input from STDIN. Print output to STDOUT. Your class should be named Solution */
  9.         int n = Convert.ToInt32(Console.ReadLine());
  10.         BigInteger result = Factorial(n);
  11.        
  12.         Console.WriteLine(result);
  13.     }
  14.    
  15.     public static BigInteger Factorial(int n)
  16.     {
  17.         BigInteger result = n;
  18.        
  19.         if ( n == 0 || n == 1) {
  20.             return 1;
  21.         }
  22.        
  23.         while (n > 1) {
  24.             n--;
  25.             result = result * n;
  26.         }
  27.        
  28.         return result;
  29.     }
  30. }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement