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

Sample Test Cases

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

Premium Question

This question needs a paid plan — upgrade, or join a class from a teacher who has one. You can read the description and sample tests, but grading is locked.

Sign in to get started