Question DSA-REC-0022
EasyWhat is the output of this code?
def f(n):
return 1 if n == 0 else n * f(n - 1)
print(f(5))
- A.
5
- B.
120
- C.
Show answer and explanation
Answer: B
f computes the factorial: 5 × 4 × 3 × 2 × 1 = 120.
Popular companies
Prepare company by company
Hiring pattern, syllabus, past questions and mocks for each company.
All companiesPractice by subject
Recursion and Backtracking question
What is the output of this code?
def f(n):
return 1 if n == 0 else n * f(n - 1)
print(f(5))
5
120
Answer: B
f computes the factorial: 5 × 4 × 3 × 2 × 1 = 120.
15
24