Advertisement
gabi11

Algorithms - 2. Recursive Factorial

Aug 31st, 2019
170
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
C# 0.51 KB | None | 0 0
  1. using System;
  2. using System.Linq;
  3.  
  4. namespace Recursion
  5. {
  6.     class Program
  7.     {
  8.         static void Main(string[] args)
  9.         {
  10.             var number = int.Parse(Console.ReadLine());
  11.  
  12.             var factorial = Factorial(number);
  13.  
  14.             Console.WriteLine(factorial);
  15.         }
  16.  
  17.         static long Factorial(int number)
  18.         {
  19.             if (number == 0)
  20.             {
  21.                 return 1;
  22.             }
  23.  
  24.             return number * Factorial(number - 1);
  25.         }
  26.     }
  27. }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement