Find LCM of two numbers in C

Find LCM of two numbers in C

What is LCM

The Least Common Multiple ( LCM ) is also referred to as the Lowest Common Multiple ( LCM ) and Least Common Divisor (LCD) .

For two integers a and b, denoted LCM(a,b), the LCM is the smallest positive integer that is evenly divisible by both a and b.

For example, LCM(2,3) = 6 and LCM(6,10) = 30

Let’s see the program

#include <stdio.h>

int main()
{
int a, b, lcm;
printf(“\nEnter two numbers: “);
scanf(“%d %d”, &a, &b);

lcm = (a > b) ? a : b;

while(1)
{
if( lcm % a == 0 && lcm % b == 0 )
{
printf(“\nLCM of %d and %d is %d\n”, a, b,lcm);
break;
}
++lcm;
}
return 0;
}