- C++ program to find factorial using recursive function
- C++ program to convert binary number to decimal and decimal to binary
- C++ program to display prime numbers between two intervals
- C++ program to print Pascal’s and Floyd’s triangle
- C++ program to print star pyramid patterns
- C++ Hello World Program
- C++ program to display Fibonacci series using loop and recursion
- C++ program to find area of the circle
- C++ program to calculate the area of the square with and without using function
- C++ program to encrypt and decrypt the string
- C++ program to convert temperature
- C++ program to check prime number
- C++ program to check palindrome number
- C++ program to make simple calculator using switch case
- C++ program for time conversion (convert time format)
- C++ program to find GCD or HCF
- C++ program to check for the power of two
- C++ program to check Armstrong number
- C++ program to check leap year
- C++ program to find LCM of two numbers

In this example, you will about C++ program to find LCM (Lowest Common Multiple) using two different methods. You will also learn to find LCM using GCD.

**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
#include <iostream>
using namespace std;
int main()
{
int num1, num2, maxValue;
cout << "Enter two numbers: " << endl;
cin >> num1 >> num2;
maxValue = (num1 > num2) ? num1 : num2;
while(1)
{
//condition of LCM
if((maxValue % num1 == 0) && (maxValue % num2 == 0))
{
cout << "LCM: " << maxValue << endl;
break;
}
++maxValue;
}
return 0;
}
```

**Output**

**Explanation**

Maximum value between two numbers is computed using conditional operator which is store in `maxValue`

.

Every time `maxValue`

is checked whether it is perfectly divisible by both numbers or not.

If `maxVaule`

is perfectly divisible, it is the LCM otherwise `maxValue`

is increased by 1.

Formula for computing LCM using GCD:

LCM = (num1 * num2) / GCD

Let’s implement the formula in C++ program.

```
//C++ program to find LCM using GCD
#include <iostream>
using namespace std;
int main()
{
int num1, num2, i, gcd, lcm;
cout << "Enter two numbers: " << endl;
cin >> num1 >> num2;
//calculation of gcd
for(i=1; i <= num1 && i <= num2; ++i)
{
if(num1 % i == 0 && num2 % i == 0)
gcd = i;
}
//calculation of lcm using gcd
lcm = (num1 * num2) / gcd;
cout << "LCM: " << lcm << endl;
return 0;
} //end main
```

**Output**

Enter two numbers: 20 30 LCM: 60