wrtie fizz buzz in rust
- User
wrtie fizz buzz in rust
Assistant
Certainly! Below is a simple implementation of the Fizz Buzz problem 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:
- Loop: We iterate through numbers from 1 to 100 using a
forloop. - Conditions:
- If the number is divisible by both 3 and 5 (i.e., divisible by 15), print "FizzBuzz".
- If the number is divisible by 3, print "Fizz".
- Loop: We iterate through numbers from 1 to 100 using a
Other models, same or similar prompt
Responses were produced in different, uncontrolled contexts (system prompts, settings, prior turns). This is not a benchmark.