c语言程序一直有一个错误!

# include <stdio.h>
# include <stdlib.h>
int gcd (int,int);
int main (void)
{
int result;
result=gcd (150,35);
printf("The gcd of 150 and 35 is %i\n",result);
result=gcd (1026,405);
printf("The gcd of 1026 and 405 is %i\n",result);
printf("The gcd of 83 and 240 is %i\n",gcd (83,240));
system("PAUSE");
return 0;
}
int gcd (int u,int v)
{
int temp;
while (v!=0)
{
temp=u%v;
u=v;
v=temp;
}
return u;
}

第1个回答  2013-10-19
gcd()有错误。
1、要分别u,v哪个大哪个小;
2、如果一开始,小的就是GCD,你的程序是搞不清的。
int gcd (int u,int v)
{
int big,small,temp;
big=(u>v)?u:v;
small=(u>v)?v:u;
temp=big%small;
while (temp!=0)
{
big=small;
small=temp;
temp=big%small;
}
return small;
}
第2个回答  2013-10-19
把错误给贴出来了,不然没人帮你仔细看代码
第3个回答  2013-10-19
程序没有问题,运行正常。
唯一有可能有问题的就是system("PAUSE");(对应# include <stdlib.h>),去掉这两行试试。
第4个回答  2013-10-19

不知道对不对啊,我把 system("PAUSE");删除了

相似回答