CodechefMay 24, 2025

Small Factorial

Hazrat Ali

Codechef

Write a program to find the factorial value of any number entered by the user.

Input Format

The first line contains an integer T, the total number of testcases. Then T lines follow, each line contains an integer N.

Output Format

For each test case, display the factorial of the given number N in a new line.

Constraints

  •  T  1000
  •  N  20

Sample 1:

Input
3 
3 
4
5
Output
6
24
120


Solution
def factorial(f):
    if f==0:
        return 1
    elif f==1:
        return 1
    else:
        return f*factorial(f-1)
n=int(input())
for i in range(n):
    num=int(input())
    print(factorial(num))





 

Comments