/*求任意两个正整数的最大公约数和(GCD)和最小公倍数(LCM)。*/
//cpp by as1138
//2010-08-13
#include <iostream>
using namespace std;
int gongyueshu(int a,int b);
int main(void)
{
int a,b,g;
while (true)
{
cout<<"请输入2个要查询的最大公约数和最小公倍数:"<<endl;
cin>>a>>b;
if (a < 0 || b < 0)
{
cout<<"请输入自然数!"<<endl;
continue;
}
g = gongyueshu(a,b);
cout<<a<<"和"<<b<<"最大公约数为:" <<g<<endl;
cout<<a<<"和"<<b<<"最小公倍数为:"<<a*b/g<<endl;
}
return 0;
}
int gongyueshu(int a,int b)
{
int ma,mi;
while (true)
{
mi = a > b ? b : a;
ma = a > b ? a : b;
a = ma - mi;
b = mi;
if (0 == a)
return ma;
}
}