Jump to content

Greatest common divisor: Difference between revisions

(→‎{{header|OCaml}}: idiomatic version)
Line 2,828:
 
=={{header|Rust}}==
===Built-innum crate===
<lang Rust>useextern crate std::num::gcd;</lang>
use num::integer::gcd;</lang>
 
===Iterative Euclid algorithm===
<lang Rust>fn gcd(mut m: inti32, mut n: inti32) -> inti32 {
while m != 0 {
let tempold_m = m;
m = n % tempm;
n = tempold_m;
}
n.abs()
Line 2,842 ⟶ 2,843:
 
===Recursive Euclid algorithm===
<lang Rust>fn gcd(m: inti32, n: inti32) -> inti32 {
if m == 0 {
{ n.abs() }
} else {
{ gcd(n % m, m) }
}
}</lang>
 
Anonymous user
Cookies help us deliver our services. By using our services, you agree to our use of cookies.