Program to find LCM

LCM stands for least common multiple is also referred to as the Lowest Common Multiple (LCM), for two integer a and b, denoted LCM (a, b). The LCM is the smallest integer that is divisible by both a and b.

For example
Find the LCM of two integer 4 and 6.

Multiples of 4 are: 4,8,12,16,20,24,and so on.
Multiples of 6 are: 6,12,18,24,30,36,42, and so on.

Common number in both multiplies are 12,24,36, so on.
12 is Lowest common multiplier 4 and 6.

Program
def LCM(a, b)
if a>b:
greater = a
else:
greater = b

while (true):
if ((greater% a==0)and (greater% b==0));
lcm = greater
break
greater+=1
return lcm

n1= int(input("First number"))
N2= int(input("Second number"))

Print(" The LCM of ",n1,"and",n2,"is", LCM(n1,n2)

Leave a Reply