C++ Program to Find LCM and HCF of Two numbers:
What is LCM?
LCM (Lowest Common Multiple) of two numbers is the smallest positive integer that is perfectly divisible by the given numbers.
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: 56
63
LCM = 504