+ 1
http://code.sololearn.com/cioeKqsAyiGb
#include <iostream>
#include <cstdlib>
#include <cmath>
using namespace std;
int gcd(int a, int b) {
while(true) {
if (a == 0) {
return b;
}
b %= a;
if (b == 0) {
return a;
}
a %= b;
}
}
int lcm(int a, int b) {
int gcdab;
gcdab = gcd(a, b);
if (gcdab != 0) {
return a/gcdab * b;
} else {
return 0;
}
}
int main(void) {
int a, b;
cout << "GCD and LCM" << endl;
cout << "Please enter the first number: ";
cin >> a;
cout << a << endl;
cout << "Please enter the second number: ";
cin >> b;
cout << b << endl;
cout << "The GCD of " << a << " and " << b << " is " << gcd(a, b) << endl;
cout << "The LCM of " << a << " and " << b << " is " << lcm(a, b) << endl;
return 0;
}



