C++ Program to Find LCM of Two Numbers

The “smallest non-zero common number” that is a multiple of both numbers is the “least common multiple of two numbers.” The least common multiple, lowest common multiple, or smallest common multiple of two integers a and b, commonly denoted by lcm, is the smallest positive integer divisible by both a and b in arithmetic and number theory.

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

return 0;
}

 

Output:

Enter two numbers

45
65
LCM = 585

What is using namespace in C++

You can define the context in which names are defined by using namespace. A namespace, in essence, specifies a scope. C++ offers a standard library that contains common features like containers and algorithms that you’ll utilize in your programs.

What is while loop in c++

The while loop in C/C++ is used when we don’t know the exact number of loop iterations ahead of time. On the basis of the test condition, the loop execution is terminated. If the condition evaluates to true, the body of the loop will be executed, and we will proceed to the update expression.

What is Post increment in c++

The post-increment operator is used to increase the value of a variable after the expression has been entirely executed. Value is first employed in an expression and then incremented in the Post-Increment.

Similar Programs