自己写的关于求最大公约数的程序,我不知道错在哪了,求指点
int gcd(int a,int b){int x,y,r;
r=x%y;
if(r=0)
return x;
else
{x=y;
y=r;
gcd(x,y);}
}
void main()
{int a,b;
scanf("%d,%d",&a,&b);
if(a>b)
printf("gcd=%d",gcd(a,b));
else
printf("gcd=%d",gcd(b,a));
}
#include "stdio.h" void main() { int a ,b,num1,num2,temp; printf("please input two number:\n"); scanf("%d%d",&num1,&num2); if(num1<num2) { temp=num1; num1=num2; num2=temp; } a=num1; b=num2; while(b!=0) /*辗除法*/ { temp=a%b; a=b; b=temp; } printf("gongyueshu:%d\n",a); printf("gongbeishu:%d\n",num1*num2/a); }你可以参考下,