Write a Python Program to Find LCM.
Least Common Multiple (LCM):
LCM, or Least Common Multiple, is the smallest multiple that is exactly divisible by two or more numbers.
Formula:
For two numbers a and b, the LCM can be found using the formula: LCM(𝑎,𝑏) =|a.b|/GCD(a,b)
For more than two numbers, you can find the LCM step by step, taking the LCM of pairs of numbers at a time until you reach the last pair.
Note: GCD stands for Greatest Common Divisor.
Program
def compute_lcm(x,y):
if(x>y):
greater=x
else:
greater=y
while(True):
if((greater % x == 0) and (greater % y == 0)):
lcm=greater
break
greater=greater+1
return lcm
if __name__=="__main__":
num1=int(input("Enter the number:"))
num2=int(input("Enter the number:"))
print("The L.C.M. is ",compute_lcm(num1,num2))
Output:
Enter the number:54
Enter the number:24
The L.C.M. is 216
More Questions
74 . Write a Python Program to Find LCM.
75 . Write a Python Program to Find HCF.
76 . Write a Python Program to Convert Decimal to Binary, Octal and Hexadecimal.
77 . Write a Python Program To Find ASCII value of a character.
78 . Write a Python Program to Make a Simple Calculator with 4 basic mathematical operations.
79 . Write a Python Program to Display Fibonacci Sequence Using Recursion.
80 . Write a Python Program to Find Factorial of Number Using Recursion.
81 . Write a Python Program to calculate your Body Mass Index.
82 . Write a Python Program to calculate the natural logarithm of any number.
83 . Write a Python Program for cube sum of first n natural numbers?
84 . Write a Python Program to find sum of array.
For latest job updates join Telegram Channel: https://t.me/sateeshm