1.输入120 72 ,输出360
2.输入120 72,输出24
Hi brother, this is very easy task. Just try to practice your programming skills.
Hope the following code helps.
HJin
===============================================================
#include <iostream>
using namespace std;
unsigned gcd(unsigned m, unsigned n); // Greatest Common Divisor
unsigned lcm(unsigned m, unsigned n); // Lowest Common Multiple
int main(int argc, char** argv)
{
unsigned m = 120;
unsigned n = 72;
cout<<lcm(m, n)<<endl;
cout<<gcd(m, n)<<endl;
return 0;
}
unsigned gcd(unsigned m, unsigned n)
{
unsigned rem;
if(n>m) // swap them so that m > n
{
int temp=n;
n=m;
m=temp;
}
while( n>0 )
{
rem=m%n;
m=n;
n=rem;
}
return m;
}
unsigned lcm(unsigned m, unsigned n) // Lowest Common Multiple
{
return m/gcd(m, n)*n;
}