Recursive Factorial
Given a single positive integer n, your task is to create a recursive function to calculate the factorial of n.
The factorial of n, denoted as n!, is the product of all positive integers less than or equal to n. For example, the factorial of 5 is 5! = 5 x 4 x 3 x 2 x 1 = 120.
The factorial of 0 is defined as 1, i.e., 0! = 1.
The first and only line of the input contains a single integer n (1 ≤ n ≤ 20), which represents the number to calculate the factorial of.
The output of the program should be a single line containing the factorial of n.
Input | Output |
|---|---|
5 | 120 |
0 | 1 |
2 | 2 |
Constraints
Time limit: 2 seconds
Memory limit: 512 MB
Output limit: 1 MB