1
1
mirror of https://github.com/theoludwig/programming-challenges.git synced 2025-05-18 12:02:53 +02:00

feat(solutions): add fizzbuzz/rust/function

This commit is contained in:
Divlo
2023-01-04 18:33:38 +01:00
parent e17156f0ab
commit 973a119487
4 changed files with 41 additions and 0 deletions

View File

@ -0,0 +1,25 @@
use std::io;
fn main() {
let mut length = String::new();
io::stdin()
.read_line(&mut length)
.expect("Failed to read `stdin` line.");
let length: usize = length
.trim()
.parse()
.expect("Failed to convert `length` as an `usize`.");
for number in 1..=length {
let is_divisible_by_3 = number % 3 == 0;
let is_divisible_by_5 = number % 5 == 0;
if is_divisible_by_3 && is_divisible_by_5 {
println!("FizzBuzz");
} else if is_divisible_by_3 {
println!("Fizz");
} else if is_divisible_by_5 {
println!("Buzz");
} else {
println!("{number}");
}
}
}