int a, b,c; int r; printf("请输入两个正整数,以逗号分隔\n"); scanf_s("%d ,%d", &a, &b); //如果a<b,交换a和b的值,此时a>b if (a<b) { c = a; a = b; b = c; } //辗转相除法 //直至余数为零,跳出循环 while (r != 0) { r = a % b; a = b; b = r; } printf("最大公约数为:%d\n", a); system("pause"); getchar(); return 0;