#include <stdio.h>
int Euclid(int m, int n);
int main() {
int m, n;
printf("输入两个整数:");
scanf("%d%d", &m, &n);
printf("最大公约数为:%d\n", Euclid(m, n));
return 0;
}
int Euclid(int m, int n) {
int r, num = 0;
printf("gcd(%d,%d)\n", m, n);
while(n != 0) {
r = m % n;
m = n;
n = r;
num++;
if(n == 0){
num++;
printf("=(%d,%d)\n", m, n);
printf("=%d\n", m);
break;
}
printf("=(%d,%d)\n", m, n);
}
printf("一共用了%d次\n", num);
return m;
}
运行效果图