โจทย์
ดูฉบับแปล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!.
เงื่อนไข
0 ≤ n ≤ 20, so the result fits a signed 64-bit integer.
ตัวอย่าง
ตัวอย่างที่ 1
อินพุต:
n = 5
ผลลัพธ์ที่คาดหวัง:
expected = 120
อินพุต:
long long n = 5;
ผลลัพธ์ที่คาดหวัง:
long long expected = 120;
อินพุต:
long n = 5;
ผลลัพธ์ที่คาดหวัง:
long expected = 120;
คำอธิบาย
1 × 2 × 3 × 4 × 5 = 120.
ตัวอย่างที่ 2
อินพุต:
n = 0
ผลลัพธ์ที่คาดหวัง:
expected = 1
อินพุต:
long long n = 0;
ผลลัพธ์ที่คาดหวัง:
long long expected = 1;
อินพุต:
long n = 0;
ผลลัพธ์ที่คาดหวัง:
long expected = 1;
คำอธิบาย
0! is defined as 1.