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

FizzBuzz

English

FizzBuzz

The classic. Walk the numbers 1 to n and, for each, decide what string to add to a list:

  • divisible by both 3 and 5 → FizzBuzz
  • divisible by 3 → Fizz
  • divisible by 5 → Buzz
  • otherwise → the number itself, as a string

Check the "both" case first, or a multiple of 15 will be caught by the 3 test alone.

ไทย

FizzBuzz

คลาสสิก. เดินผ่านเลข 1 ถึง n และสำหรับแต่ละเลข ตัดสินใจว่าจะเพิ่มอะไรลงในลิสต์:

  • หารด้วยทั้ง 3 และ 5 ลงตัว → FizzBuzz
  • หารด้วย 3 ลงตัว → Fizz
  • หารด้วย 5 ลงตัว → Buzz
  • อื่นๆ → ตัวเลขเอง ในรูปสตริง

ตรวจสอบกรณี "both" ก่อน, มิฉะนั้นعددที่หารด้วย 15 ลงตัวจะถูกจับโดยเงื่อนไข 3 เพียงอย่างเดียว

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

IGCSE, A-Level & AP