Easy 0 solved 0% acceptance

Factorial

Multiply all positive integers up to n.

Problem

The factorial of n, written n!, is 1 × 2 × … × n. By definition 0! = 1.

Implement factorial(n).

Input

n: A non-negative integer.

Output

Return n!.

Constraints

0 ≤ n ≤ 20, so the result fits a signed 64-bit integer.

Examples

Example 1
Input:
n = 5

Expected output:
expected = 120
Input:
long long n = 5;

Expected output:
long long expected = 120;
Input:
long n = 5;

Expected output:
long expected = 120;

Explanation

1 × 2 × 3 × 4 × 5 = 120.

Example 2
Input:
n = 0

Expected output:
expected = 1
Input:
long long n = 0;

Expected output:
long long expected = 1;
Input:
long n = 0;

Expected output:
long expected = 1;

Explanation

0! is defined as 1.

Learn from others

Community solutions

No published solutions yet. Solve this challenge to share the first one.