任意两个整数求解其最大公约数的方法有很多,但辗转相除法非常经典和简洁,当然还有枚举法等方法求解最大公约数,各位看官请自行取舍!
光阴似箭,日月如梭!可能编写的程序会有些复杂,不简洁,但是不要紧,一起慢慢来,一起举杯敬明天!
void main()
{
int m,n,c,r=0,temp;
printf("请输入两个数:");
scanf("%d,%d",&m,&n);
if(m>=n)
{
c=m%n;
if(c==0)
{
printf("the greatest common divisor:%d",n);
}
else
{
while(c!=0)
{
m=n;
n=c;
c=m%n;
}
printf("the greatest common divisor:%d",n);
}
}
else
{
r=m;
m=n;
n=r;
c=m%n;
if(c==0)
{
printf("the greatest common divisor:%d",n);
}
else
{
while(c!=0)
{
m=n;
n=c;
c=m%n;
}
printf("the greatest common divisor:%d",n);
}
}
}