In this program, we have explained how to find the LCM (Least Common Multiple) numbers using the c++ programming language.

below is the formula to calculate the LCM (Least Common Multiple) numbers from given numbers.

We are going to find the LCM number of 24 and 60. On the basis of above LCM formula:

1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 | #include <iostream> using namespace std; int main() { int a, b, max; cout << "Enter two numbers to find LCM: "; cin >> a >> b; // maximum value between a and b is stored in max max = (a > b) ? a : b; do { if (max % a == 0 && max % b == 0) { cout << "LCM is = " << max; break; } else ++max; } while (true); return 0; } |

Enter two numbers to find LCM: 24

60

LCM is: 120

If you like FreeWebMentor and you would like to contribute, you can write an article and mail your article to [email protected] Your article will appear on the FreeWebMentor main page and help other developers.

- C++ program to reverse a single linked list
- c++ program to remove vowels from a string
- CPP program to check if a number is Wagstaff prime or not
- CPP program to remove punctuation from a given string
- C++ program to find minimum players required to win the game anyhow
- C++ program to print primes smaller than n using Sieve of Sundaram
- C++ program to find count of divisors in n!
- C++ implementation to sort the given matrix
- C++ program to find Majority element in an array
- How to convert a string to integer array in CPP

Article Tags: c program, c programs, c++ program to find lcm, C++ Tutorial, lcm program example, lcm program example with output, lcm program in c++, lcm program output

We use cookies to ensure that we give you the best experience on our website. If you continue to use this site we will assume that you are happy with it.Ok