Skip to content

Instantly share code, notes, and snippets.

@mzaglia
Created March 15, 2018 16:54
Show Gist options
  • Save mzaglia/1324632fdec63c5949779d186ceac5a0 to your computer and use it in GitHub Desktop.
Save mzaglia/1324632fdec63c5949779d186ceac5a0 to your computer and use it in GitHub Desktop.
gcd_rust created by mzaglia - https://repl.it/@mzaglia/gcdrust
fn gcd_rec(value1: i32, value2: i32) -> i32
{
if value2 == 0
{
return value1;
}
return gcd_rec(value2, (value1 % value2));
}
fn gcd(mut value1: i32,mut value2: i32) -> i32
{
if value1 == 0 || value2 == 0
{
return 0;
}
while
{
let aux: i32 = value1;
value1 = value2;
value2 = aux % value2;
value2 != 0
}{ }
return value1;
}
fn main() {
println!("{}", gcd(150, 20));
println!("{}", gcd_rec(150, 20));
}
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment