Python Program For LCM of 2 numbers

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 in numbers_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.

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

OUTPUT:


1 comment

JavaFX Scene Builder

  This is an article about the JavaFX Scene Builder. You will get a short introduction about the installation and usage of the software. The...