Python program to find the HCF of two given numbers.

preview_player
Показать описание

Рекомендации по теме
Комментарии
Автор

HCF of any two numbers is a factor which is common in both but it should be also the highest common.
num1 = int(input("Enter the num1: "))
num2 = int(input("Enter the num2: "))

mult_1 = set()
mult_2 = set()

for i in range(1, num1+1):
if num1%i == 0:
mult_1.add(i)

for j in range(1, num2+1):
if num2%j == 0:
mult_2.add(j)
print(mult_1)
print(mult_2)

common_factors = mult_1.intersection(mult_2)
a = list(common_factors)
a.reverse()
print(f'hcf = {a[0]}')

sachinsuman
Автор

how do we solve the problem if we have a user - inputted list of numbers rather than just two numbers?

jasonhilton