LCM of two number in python by R4R Team

What is LCM-
LCM stands for lowest common multiple

Example -

let we have a two number 10 and 12 then common multiple of these two number is 60,120,180,....
but lowest one is 60,
so we can conclude that LCM of 10 and 12 is 60

Program -

print("Enter first number")
a=int(input())
print("Enter second number")
b=int(input())
m=max(a,b)
while(1):
if m%a==0 and m%b==0:
print("LCM is - "+str(m))
break
m=m+1


output -

Enter first number
12
Enter second number
18
LCM is - 36

Enter first number
10
Enter second number
12
LCM is - 60

Enter first number
23
Enter second number
25
LCM is - 575


-In this program, we find the lcm of two number, firstly we choose the greatest number out of two, then we increase that number one by one and check for both input number that it is multiple of it or not.


Leave a Comment:
Search
Categories
R4R Team
R4Rin Top Tutorials are Core Java,Hibernate ,Spring,Sturts.The content on R4R.in website is done by expert team not only with the help of books but along with the strong professional knowledge in all context like coding,designing, marketing,etc!