辗转相除
int n,v,temp = 0,max,min;
n = 50;
v = 25;
if (n > v) {
max = n;
min = v;
}else{
max = v;
min = n;
}
while (min != 0) {
temp = max % min;
max = min;
min = temp;
}
NSLog(@"最大公约数-->%i",max);
NSLog(@"最小公倍数-->%i",n*v/max);
辗转相减
int n,v,temp = 0,max,min;
n = 10;
v = 10;
if (n > v) {
max = n;
min = v;
}else{
max = v;
min = n;
}
while (min != 0) {
temp = max - min;
max = min;
min = temp;
}
NSLog(@"最大公约数-->%i",max);
NSLog(@"最小公倍数-->%i",n*v/max);
网友评论