调用gcd()函数求两个整数最大公约数 不知道哪错了
#include<stdio.h>int gcd(int a,int b)
{
int temp;
int remainder;
if(a<b)
{
temp = a; a = b; b = temp;
}
remainder=a%b;
while(remainder!=0)
{
a=b;
b=remainder;
}
return b;
}
void main()
{
int x,y;
int fac;
printf("Please input two num:\n");
scanf("%d %d",&x,&y);
fac=gcd(x,y);
printf("The great common divisor is%d\n",fac);
}
while(remainder!=0)
{
a=b;
b=remainder;
}
这个循环没有改变remainder所以要么不进入循环,要么是死循环 哦哦,懂了
页:
[1]