求27复制#include<stdio.h>intmain(){
int m, n, a, b, t, c;
printf("Input two integer numbers:\n");
scanf("%d%d", &a, &b);
m = a;
n = b;
while (b!= 0) {
c = a%b;
a = b;
b = c;
}
printf("The largest common divisor:%d\n", a);
return0;
}
(二)相减法
原理:a。
示例:
求27复制#include<stdio.h>intmain(){
int m, n, a, b, c;
printf("Input two integer numbers:\n");
scanf("%d%d", &a, &b);
m = a;
n = b;
while (a!= b) {
if (a > b)
a = a - b;
else b = b - a;
}
printf("The largest common divisor:%d\n", a);
return0;
}
(三)穷举法
原理:从1。
示例:
求6复制#include<stdio.h>intmain(){
int m, n, a, b, i, t;
printf("Input two integer numbers:\n");
scanf("%d%d", &a, &b);
m = a;
n = b;
for (i = 1; i <= a; i++) {
if (a%i == 0 && b%i == 0)
t = i;
}
printf("The largest common divisor:%d\n", t);
return0;
}