FizzBuzz
Write the classic FizzBuzz program! Loop through the numbers 1 to 20 and print:
FizzBuzzif the number is divisible by both 3 and 5Fizzif the number is divisible by 3Buzzif 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 == 0for FizzBuzz,i % 3 == 0for Fizz,i % 5 == 0for Buzz - Use
else ifto chain the conditions
rust
fn main() {
}