Advertisement
Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- //https://www.hackerrank.com/challenges/30-recursion
- using System;
- using System.Collections.Generic;
- using System.IO;
- using System.Linq;
- class Solution
- {
- static int factorial(int n)
- {
- // Complete this function
- int outputNumber = 1;
- if(n > 1)
- {
- outputNumber = n * factorial(n - 1);
- }
- return outputNumber;
- }
- static void Main(String[] args)
- {
- int n = Convert.ToInt32(Console.ReadLine());
- int result = factorial(n);
- Console.WriteLine(result);
- }
- }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement