C++ Programming Code Examples C++ > Mathematics Code Examples C++ Program to Find LCM C++ Program to Find LCM Examples on different ways to calculate the LCM (Lowest Common Multiple) of two integers using loops and decision making statements. LCM of two integers a and b is the smallest positive integer that is divisible by both a and b. LCM = 36 In above program, user is asked to integer two integers number1 and number2 and largest of those two numbers is stored in max. It is checked whether max is divisible by number1 and number2, if it's divisible by both numbers, max (which contains LCM) is printed and loop is terminated. If not, value of max is incremented by 1 and same process goes on until max is divisible by both number1 and number2. #include <iostream> using namespace std; int main() { int number1, number2, max; cout << "Enter two numbers: "; cin >> number1 >> number2; // maximum value between number1 and number2 is stored in max max = (number1 > number2) ? number1 : number2; do { if (max % number1 == 0 && max % number2 == 0) { cout << "LCM = " << max; break; } else ++max; } while (true); return 0; }