Computer Science, asked by farhaz999, 1 month ago

Write a Python Program to find the L.C.M. of two input number​

Answers

Answered by sahanatiruppur
0

Answer:Note: To test this program, change the values of num1 and num2.

This program stores two number in num1 and num2 respectively. These numbers are passed to the compute_lcm() function. The function returns the L.C.M of two numbers.

In the function, we first determine the greater of the two numbers since the L.C.M. can only be greater than or equal to the largest number. We then use an infinite while loop to go from that number and beyond.

Explanation:def compute_lcm(x, y):

  # choose the greater number

  if x > y:

      greater = x

  else:

      greater = y

  while(True):

      if((greater % x == 0) and (greater % y == 0)):

          lcm = greater

          break

      greater += 1

  return lcm

num1 = 54

num2 = 24

print("The L.C.M. is", compute_lcm(num1, num2))

Similar questions