Skip to content

Instantly share code, notes, and snippets.

@kobus1998
Created March 9, 2018 10:33
Show Gist options
  • Save kobus1998/5d9610aab3443caa923b3590efd6f289 to your computer and use it in GitHub Desktop.
Save kobus1998/5d9610aab3443caa923b3590efd6f289 to your computer and use it in GitHub Desktop.
Rust fizzbuzz
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