Practice

Recursive Factorial Function

MEDIUMProcedures & Functions6 marks

Write a recursive function Factorial(N) that returns the factorial of a non-negative integer.

Use 0 and 1 as base cases. The function must call itself for larger values.

Input: One integer from 0 to 10. Output: Its factorial.

Example:

Input:  5
Output: 120
Premium is coming soon. All grading features are currently unlocked.

Sample Test Cases

Test 1: Typical factorial
Inputs: 5
Expected: 120
Test 2: Zero base case
Inputs: 0
Expected: 1