辗转相除求最大公约数,这个程序是哪里不对吗?
来源:学生作业帮 编辑:神马作文网作业帮 分类:综合作业 时间:2024/10/09 20:21:51
辗转相除求最大公约数,这个程序是哪里不对吗?
#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)
{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写错了,你对比一下.
#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写错了,你对比一下.
下面的程序是用辗转相除法求两个正整数的最大公约数,请填空.
辗转相除法求最大公约数
C语言程序:用“辗转相除法”求两个正整数的最大公约数(程序填空)
C语言 用辗转相除法求最大公约数 编写C语言程序
C语言程序填空:用辗转相除法求两个整数的最大公约数、最小公倍数.
C语言程序 设计:用辗转相除法求两个正整数的最大公约数
C语言程序填空:用辗转相除法求两个整数的最大公约数 帮帮
c语言编写程序用辗转相除法求两个正整数m和n的最大公约数
高中VB程序题用辗转相除法求最大公约数.已知用辗转相除法求两个正整数m、n的最大公约数的算法如下:(用num1,num2
用辗转相除法求最大公约数!
6731.2809怎么辗转相除法求最大公约数
辗转相除法为什么能求最大公约数