Created
March 15, 2018 16:54
-
-
Save mzaglia/1324632fdec63c5949779d186ceac5a0 to your computer and use it in GitHub Desktop.
gcd_rust created by mzaglia - https://repl.it/@mzaglia/gcdrust
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 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