Computer Science, asked by shreyoshikar707, 7 months ago

Write a Python script to input two numbers and print their lcm (Least common multiple) and gcd (greatest Common divisor).​

Answers

Answered by iymanmalik1994
5

Answer:

H.C.F of 12 and 14 is 2.

Source Code: Using Loops

# Python program to find H.C.F of two numbers

# define a function

def compute_hcf(x, y):

# choose the smaller number

if x > y:

smaller = y

else:

smaller = x

for i in range(1, smaller+1):

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

hcf = i

return hcf

num1 = 54

num2 = 24

print("The H.C.F. is", compute_hcf(num1, num2))

Output

The H.C.F. is 6

# Python Program to find the L.C.M. of two input number

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))

Output

The L.C.M. is 216

Similar questions