30 days of code: Day 9

https://www.hackerrank.com/challenges/30-recursion/

Recursions were new to me. Haven’t had to use them with my previous apps. Or maybe I could have? Learned Summation, Factorial, and Exponentiation.

Sample Input
3

Sample Output
6

int n = Convert.ToInt32(Console.ReadLine());
static int Factorial(int n)
{
    if (n == 1)
    {
        return 1;
    }
    else
    {
        return n * Factorial(n - 1);
    }
}

Console.WriteLine(Factorial(n));

Leave a Reply

Your email address will not be published. Required fields are marked *