write fizz buzz in rust
- User
write fizz buzz in rust
Assistant
I'll write a Fizz Buzz implementation in Rust. Here's a clean, idiomatic solution:
fn main() { for number in 1..=100 { match (number % 3 == 0, number % 5 == 0) { (true, true) => println!("FizzBuzz"), (true, false) => println!("Fizz"), (false, true) => println!("Buzz"), _ => println!("{}", number) } } }This Rust implementation does the following:
- Uses a
forloop to iterate through numbers 1 to 100 (inclusive with1..=100) - Uses pattern matching (
match) to handle the different Fizz Buzz conditions - Checks divisibility by 3 and 5 using the modulo operator
% - Prints "FizzBuzz" for numbers divisible by both 3 and 5
- Prints "Fizz" for numbers divisible by 3
- Prints "Buzz" for numbers divisible by 5
- Uses a
Other models, same or similar prompt
Responses were produced in different, uncontrolled contexts (system prompts, settings, prior turns). This is not a benchmark.