Task
To find LCM of 2 numbers
Approach
- Read two input numbers using
input()
. - Find the minimum of 2 numbers, using
min()
function and store the value innumbers_min
variable. - Now run a while loop and check whether both numbers are divisible by the
numbers_min
variable which we got in the previous step.- if both numbers are divisible by
numbers_min
print the value as LCM and break the loop - if not, increment
numbers_min
value and continue while loop.
- if both numbers are divisible by
Program
num1 = int(input("Enter first number: \t"))
num2 = int(input("Enter second number: \t"))
numbers_min = min(num1, num2)
while(1):
if(numbers_min % num1 == 0 and numbers_min % num2 == 0):
print("LCM of two number is: ", numbers_min)
break
numbers_min += 1
Thanks for sharing this blog. This article gives lot of information.
ReplyDeletePython Online Training in Hyderabad
Python Institute in Hyderabad
Python Course in Hyderabad