C++ Program to Find LCM and HCF of two numbers

C++ Program to Find LCM and HCF of two numbers: calculate the LCM (Lowest Common Multiple) of two integers using loops and decision making statements. HCF and LCM of the two numbers on the output screen as shown here in the following program.

C++ Program to Find LCM and HCF of two numbers

#include <iostream>
using namespace std;
int main() {
    int n1, n2, max;
    cout << "Enter two numbers: ";
    cin >> n1 >> n2;
    max = (n1 > n2) ? n1 : n2;
    do {
        if (max % n1 == 0 && max % n2 == 0) {
            cout << "LCM = " << max;
            break;
        } else
            ++max;
    } while (true);
    return 0;
}

Output of Program

Enter two numbers: 15
17
LCM = 255