mirror of
https://github.com/theoludwig/programming-challenges.git
synced 2024-12-08 00:45:29 +01:00
feat(solutions): add fizzbuzz/rust/function
This commit is contained in:
parent
e17156f0ab
commit
973a119487
7
challenges/fizzbuzz/solutions/rust/function/Cargo.lock
generated
Normal file
7
challenges/fizzbuzz/solutions/rust/function/Cargo.lock
generated
Normal file
@ -0,0 +1,7 @@
|
|||||||
|
# This file is automatically @generated by Cargo.
|
||||||
|
# It is not intended for manual editing.
|
||||||
|
version = 3
|
||||||
|
|
||||||
|
[[package]]
|
||||||
|
name = "rust_application"
|
||||||
|
version = "1.0.0"
|
6
challenges/fizzbuzz/solutions/rust/function/Cargo.toml
Normal file
6
challenges/fizzbuzz/solutions/rust/function/Cargo.toml
Normal file
@ -0,0 +1,6 @@
|
|||||||
|
[package]
|
||||||
|
name = "rust_application"
|
||||||
|
version = "1.0.0"
|
||||||
|
edition = "2021"
|
||||||
|
|
||||||
|
[dependencies]
|
3
challenges/fizzbuzz/solutions/rust/function/README.md
Normal file
3
challenges/fizzbuzz/solutions/rust/function/README.md
Normal file
@ -0,0 +1,3 @@
|
|||||||
|
# fizzbuzz/rust/function
|
||||||
|
|
||||||
|
Created by [@Divlo](https://github.com/Divlo) on 4 January 2023.
|
25
challenges/fizzbuzz/solutions/rust/function/src/main.rs
Normal file
25
challenges/fizzbuzz/solutions/rust/function/src/main.rs
Normal 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}");
|
||||||
|
}
|
||||||
|
}
|
||||||
|
}
|
Loading…
x
Reference in New Issue
Block a user