1.

Write a Python code to find the L.C.M. of two numbers?

Answer»

Method I using functions:

def 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 + = 1

return lcm

num 1 = int (input(“Enter first number : “))

num 2 = int (input(“Enter second number : “))

print (“The L.C.M of” , numl, “and” , num, “is” , lcm(num1, num2))

Method II

(without using functions)

a = int (input (“Enter the first number :”))

b = int (input (“Enter the second number :”))

if a > b:

mini = a

else:

min 1 = b

while(1):

if (min 1 % a = = 0 and mini 1 % b = = 0):

print (“LCM is:” , mini)

break

mini = min 1 + 1

Output:

Enter the first number: 15

Enter the second number: 20

LCM is: 60



Discussion

No Comment Found