Recursive Factorial
EasyPractice library · +10 XPrecursionmath
The factorial of a non-negative integer N, denoted by N!, is the product of all positive integers less than or equal to N. By definition, 0! = 1.
Calculate and print the factorial of a given non-negative integer N.
Input
A single line containing a non-negative integer N.
Output
A single line containing the integer N!.
Constraints
0 <= N <= 15
Time limit 1 s (native code; slower languages get more)Memory 256 MB11 hidden tests
Example 1
Input
5
Output
120
5! = 5 * 4 * 3 * 2 * 1 = 120
Example 2
Input
0
Output
1
0! is defined as 1
Hints
# Read the input from stdin and print the answer.
import sys
def main():
data = sys.stdin.read().split()
# your code here
main()
Example 1 input
5
Example 2 input
0