辗转相除求最大公约数,这个程序是哪里不对吗?#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/07/02 02:04:32
![辗转相除求最大公约数,这个程序是哪里不对吗?#includeint main(){int gcd(int x,int y);int a,b,d;printf(](/uploads/image/z/4021249-49-9.jpg?t=%E8%BE%97%E8%BD%AC%E7%9B%B8%E9%99%A4%E6%B1%82%E6%9C%80%E5%A4%A7%E5%85%AC%E7%BA%A6%E6%95%B0%2C%E8%BF%99%E4%B8%AA%E7%A8%8B%E5%BA%8F%E6%98%AF%E5%93%AA%E9%87%8C%E4%B8%8D%E5%AF%B9%E5%90%97%3F%23includeint+main%28%29%7Bint+gcd%28int+x%2Cint+y%29%3Bint+a%2Cb%2Cd%3Bprintf%28%22please+input+the+number+from+the+bigger+to+the+smaller%3A%22%29%3B%2F%2F%E4%BB%8E%E5%A4%A7%E5%88%B0%E5%B0%8F%E8%BE%93%E5%85%A5%E4%B8%A4%E4%B8%AA%E6%95%B0%2C%E4%BE%BF%E4%BA%8E%E5%90%8E%E9%9D%A2%E8%BE%97%E8%BD%AC%E7%9B%B8%E9%99%A4%E8%AE%A1%E7%AE%97scanf%28%22%25d%2C%25d)
辗转相除求最大公约数,这个程序是哪里不对吗?#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写错了,你对比一下.