chatgpt-4o-latest-20250326· OpenAI
LMArena Human Preference 140K
write fizzbust in rust
- User
write fizzbust in rust
- Assistant
Sure! Here's a simple implementation of the classic FizzBuzz program in Rust:
fn main() { for i in 1..=100 { if i % 15 == 0 { println!("FizzBuzz"); } else if i % 3 == 0 { println!("Fizz"); } else if i % 5 == 0 { println!("Buzz"); } else { println!("{}", i); } } }Explanation:
- The
forloop iterates from 1 to 100 (inclusive). %is the modulo operator in Rust.- If a number is divisible by both 3 and 5 (i.e., 15), it prints "FizzBuzz".
- If only divisible by 3, it prints "Fizz".
- If only divisible by 5, it prints "Buzz".
- Otherwise, it prints the number itself.
You can run this code using
cargo runor by pasting it into an online Rust playground like https://play.rust-lang.org. - The
Other models, same or similar prompt
Responses were produced in different, uncontrolled contexts (system prompts, settings, prior turns). This is not a benchmark.