作业帮 > 综合 > 作业

辗转相除求最大公约数,这个程序是哪里不对吗?

来源:学生作业帮 编辑:灵鹊做题网作业帮 分类:综合作业 时间:2024/05/22 04:16:22
辗转相除求最大公约数,这个程序是哪里不对吗?
#include
int main()
{int gcd(int x,int y);
int a,b,d;
printf("please input the number from the bigger to the smaller:");//从大到小输入两个数,便于后面辗转相除计算
scanf("%d,%d,&a,&b");
d=gcd(a,b);//调用函数
printf("the greatest common divisor is %d\n",d);
return 0;
}
int gcd(int x,int y)
{int c;
while(y!=0)
{c=x%y;
x=y;
y=c;}
return (x);//输出除数
}
辗转相除求最大公约数,这个程序是哪里不对吗?
修改如下:
#include
int main()
{int gcd(int x,int y);
int a,b,d;
printf("please input the number from the bigger to the smaller:");//从大到小输入两个数,便于后面辗转相除计算
scanf("%d %d",&a,&b);
d=gcd(a,b);//调用函数
printf("the greatest common divisor is %d\n",d);
return 0;
}
int gcd(int x,int y)
\x05{int c;
\x05while(y!=0)\x05\x05
{c=x%y;
x=y;
y=c;}
return (x);//输出除数
}
上面的scanf写错了,你对比一下.