辗转相除求最大公约数,这个程序是哪里不对吗?#includeint 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

来源:学生作业帮助网 编辑:作业帮 时间:2024/05/06 15:13:26

辗转相除求最大公约数,这个程序是哪里不对吗?#includeint 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
辗转相除求最大公约数,这个程序是哪里不对吗?
#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);//输出除数
}

辗转相除求最大公约数,这个程序是哪里不对吗?#includeint 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
修改如下:
#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写错了,你对比一下.