代码如下
/question 1/
#include <stdio.h>
#include <math.h>
int main()
{int a,b,i,c,d;
printf("please input the both number:");
scanf("%d,%d",&a,&b);
for(i=a;i>1;i--)
{c=a%i;d=b%i;
if(c==d==0)
{printf("the greatest commen divisor:%d",i);
break;}
}
return 0;
}
请问该如何修改
这句是这样的:if(c==0 && d==0) //(c==d==0),修改完善如下,供参考:
#include <stdio.h>
#include <math.h>
int main()
{
int a,b,i,c,d;
printf("please input the both number:");
scanf("%d%d",&a,&b);
for(i=a<b?a:b;i>1;i--)//修改
{
c=a%i;d=b%i;
if(c==0 && d==0) //(c==d==0)
{
printf("the greatest commen divisor:%d",i);
break;
}
}
return 0;
}