Skip to content

Commit

Permalink
Solution for #3
Browse files Browse the repository at this point in the history
- Implemented to rust.
  • Loading branch information
ademclk committed Aug 15, 2022
1 parent 51e7453 commit 5300194
Showing 1 changed file with 24 additions and 0 deletions.
24 changes: 24 additions & 0 deletions challenge/fizz_buzz/main.rs
Original file line number Diff line number Diff line change
@@ -0,0 +1,24 @@
use std::io;

fn fizz_buzz(n : i32) {
for i in 1..n+1 {
if i % 3 == 0 && i % 5 == 0 {
println!("FizzBuzz");
} else if i % 3 == 0 {
println!("Fizz");
} else if i % 5 == 0 {
println!("Buzz");
} else {
println!("{}", i);
}
}
}

fn main() {
// User integer input
println!("Enter a number: ");
let mut input = String::new();
io::stdin().read_line(&mut input).expect("Failed to read line");
let n: i32 = input.trim().parse().expect("Please type a number!");
fizz_buzz(n);
}

0 comments on commit 5300194

Please sign in to comment.