求两个数的最大公约数:
int divisor(int a,int b)
{
int temp;
if(a<b)
{
temp = a;
a = b;
b = temp;
}
while(b)
{
temp = a%b;
a = b;
b = temp;
}
return a;
}
利用递归函数表示
int divisor(int a,int b)
{
if(!b)
return a;
else
return divisor(b,a%b);
}
两个数的最小公倍数==两个数成绩除以最大公约数!
int multiple(int a,int b)
{
int temp = diversor(int a,int b);
return (a*b/temp);
}