Exerpad
🔥0
0 XP
Lv.1 Beginner
Log In

FizzBuzz

Write the classic FizzBuzz program! Loop through the numbers 1 to 20 and print:

  • FizzBuzz if the number is divisible by both 3 and 5
  • Fizz if the number is divisible by 3
  • Buzz if the number is divisible by 5
  • The number itself otherwise

Expected output:

text
1
2
Fizz
4
Buzz
Fizz
7
8
Fizz
Buzz
11
Fizz
13
14
FizzBuzz
16
17
Fizz
19
Buzz

Hints:

  • Check divisible by 15 (both 3 and 5) first — order matters!
  • Use if i % 15 == 0 for FizzBuzz, i % 3 == 0 for Fizz, i % 5 == 0 for Buzz
  • Use else if to chain the conditions
rust
fn main() {
}