Practice

Factorial

MEDIUMProcedures & Functions

Read a non-negative integer N (0 ≤ N ≤ 12). Output N! (N factorial).

Recall: 0! = 1, and N! = N × (N−1) × … × 1.

Input: A non-negative integer N. Output: The value of N!.

Example:

Input:  5
Output: 120

Sample Test Cases

Test 1: 5!
Inputs: 5
Expected: 120
Test 2: 0! = 1
Inputs: 0
Expected: 1
Test 3: 1!
Inputs: 1
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
Factorial | Cambridge pseudocode practice