Greatest common divisor iterative
fn gcd(mut m: i32, mut n: i32) -> i32 {
while m != 0 {
let old_m = m;
m = n % m;
n = old_m;
}
n.abs()
}
fn main() {
println!("Greatest Common Divisor = {} ",gcd(115, 230));
}
Greatest common divisor iterative
fn gcd(mut m: i32, mut n: i32) -> i32 {
while m != 0 {
let old_m = m;
m = n % m;
n = old_m;
}
n.abs()
}
fn main() {
println!("Greatest Common Divisor = {} ",gcd(115, 230));
}
Greatest common divisor iterative
#include<stdio.h>
int gcd_iter(int u, int v) {
if (u < 0) u = -u;
if (v < 0) v = -v;
if (v) while ((u %= v) && (v %= u));
return (u + v);
}
int main() {
printf("Greatest Common Divisor = %i", gcd_iter(115, 230));
}
Copyright © 2021 Codeinu
Forgot your account's password or having trouble logging into your Account? Don't worry, we'll help you to get back your account. Enter your email address and we'll send you a recovery link to reset your password. If you are experiencing problems resetting your password contact us