#include using namespace std; int num0, num1; int lcm, larger, smaller, hold; // This assignment is worth 5 points. int main() { cout << "Enter two numbers: "; cin >> num0 >> num1; cin.ignore(); lcm = num0 * num1; // Find the LCM by working backwards larger = num0 > num1 ? num0 : num1; smaller = num0 < num1 ? num0 : num1; hold = lcm; /* * The largest possible LCM is the product of the two numbers. * The smallest possible LCM is the larger of the two numbers. * This solution solves for LCM without using the GCF. * Otherwise, simply find the GCF and divide the product of the two * input values by their GCF to get the LCM. */ while(hold > larger) { hold -= smaller; if(hold % larger == 0 && hold % smaller == 0) lcm = hold; } cout << "LCM between " << num0 << " and " << num1 << " is " << lcm << ".\n"; return 0; }