使用 while 和 if
include
int main()
{
int n1, n2;
printf("输入两个数,以空格分隔: ");
scanf("%d %d",&n1,&n2);
while(n1!=n2)
{
if(n1 > n2)
n1 -= n2;
else
n2 -= n1;
}
printf("GCD = %d",n1);
return 0;
}
运行结果:
输入两个数,以空格分隔: 81 153
GCD = 9