A Program to Find LCM

In this example, we are giving a program to find LCM(least common multiple).


Program to find LCM:

  1. # Find LCM
  2. def compute_lcm(x, y):
  3. if x > y:
  4. greater = x
  5. else:
  6. greater = y
  7. while(True):
  8. if ((greater % x == 0) and (greater % y == 0)):
  9. lcm = greater
  10. break
  11. greater += 1
  12. return lcm
  13. num1 = int(input('Enter 1st number: '))
  14. num2 = int(input('Enter 2nd number: '))
  15. print("The L.C.M. is", compute_lcm(num1, num2))

Output:

Enter 1st number: 65
Enter 2nd number: 35
The L.C.M. is 455