Answers for "rust fizzbuzz"

0

rust fizzbuzz

fn main() {
  // using if statements
  for i in 1..102 {
    if i % 15 == 0 { println!("FizzBuzz") }
    else if i % 3 == 0 { println!("Fizz") }
    else if i % 5 == 0 { println!("Buzz") }
    else { println!("{}", i) }
  }
  // using match
  for i in 1..102 {
    match (i%3, i%5) {
    (0, 0) => println!("FizzBuzz"),
    (0, _) => println!("Fizz"),
    (_, 0) => println!("Buzz"),
    (_, _) => println!("{}", i)
    }
  }
}
Posted by: Guest on March-14-2021

Browse Popular Code Answers by Language