Robotics & Artificial Intelligence

Write a Python program to input two numbers and find their HCF and LCM.

Python Control Flow

1 Like

Answer

a = int(input("Enter first number: "))
b = int(input("Enter second number: "))
x = a
y = b
while b != 0:
    r = a % b
    a = b
    b = r
hcf = a
lcm = (x * y) // hcf
print("HCF:", hcf)
print("LCM:", lcm)

Output

Enter first number: 12
Enter second number: 18
HCF: 6
LCM: 36

Answered By

3 Likes


Related Questions