Skip to content · ⁨ข้ามไปยังเนื้อหา⁩

Factorial (mind the size) · ⁨แฟกทอเรียล (ระวังขนาด)⁩

English

Factorial (mind the size)

n! is 1 × 2 × … × n, and 0! is 1. It grows fast — 20! is over two billion billion — so the method returns a long, not an int, or the answer would overflow. Multiply from 2 up to n.

ไทย

ฟักทอเรียล (ระวังเรื่องขนาด)

n! คือ 1 × 2 × … × n และ 0! คือ 1 มันเติบโต เร็วมาก — 20! มีค่าเกินสองพันล้านล้าน — ดังนั้นวิธีการนี้จะคืนค่าเป็น long ไม่ใช่ int มิฉะนั้นคำตอบจะเกินขอบเขต (overflow) ให้คูณตั้งแต่ 2 ขึ้นไปจนถึง n

Log in or create account · ⁨เข้าสู่ระบบหรือสร้างบัญชี⁩

IGCSE, A-Level & AP