Created
March 9, 2018 10:33
-
-
Save kobus1998/5d9610aab3443caa923b3590efd6f289 to your computer and use it in GitHub Desktop.
Rust fizzbuzz
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
fn main() { | |
let max: i32 = 101; | |
let mut l: Vec<String> = Vec::new(); | |
for i in 0..max | |
{ | |
l.push(fizz_buzz(i)); | |
} | |
for item in l | |
{ | |
println!("{}", item); | |
} | |
} | |
fn dividable(num: i32, divide: i32) -> bool | |
{ | |
if num % divide == 0 | |
{ | |
return true | |
} | |
return false | |
} | |
fn fizz_buzz(num: i32) -> String | |
{ | |
let result: String; | |
if dividable(num, 3) && dividable(num, 5) | |
{ | |
result = String::from("FizzBuzz"); | |
} | |
else if dividable(num, 3) | |
{ | |
result = String::from("Fizz"); | |
} | |
else if dividable(num, 5) | |
{ | |
result = String::from("Buzz"); | |
} | |
else | |
{ | |
result = num.to_string(); | |
} | |
result | |
} |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment