Advertisement
minnera

#30daysofcode #day9

Oct 7th, 2017
75
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
C# 0.57 KB | None | 0 0
  1. //https://www.hackerrank.com/challenges/30-recursion
  2.  
  3. using System;
  4. using System.Collections.Generic;
  5. using System.IO;
  6. using System.Linq;
  7. class Solution
  8. {
  9.  
  10.     static int factorial(int n)
  11.     {
  12.         // Complete this function
  13.         int outputNumber = 1;
  14.  
  15.         if(n > 1)
  16.         {
  17.             outputNumber = n * factorial(n - 1);
  18.         }
  19.  
  20.         return outputNumber;
  21.     }
  22.  
  23.     static void Main(String[] args)
  24.     {
  25.         int n = Convert.ToInt32(Console.ReadLine());
  26.         int result = factorial(n);
  27.         Console.WriteLine(result);
  28.     }
  29. }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement