ง่าย 0 ข้อที่แก้แล้ว อัตราผ่าน 0%

Factorial

Multiply all positive integers up to n.

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.

เรียนรู้จากคนอื่น

แนวทางจากชุมชน

ยังไม่มีวิธีทำที่เผยแพร่ ลองแก้โจทย์นี้เพื่อแชร์วิธีแรก