0% found this document useful (0 votes)
40 views1 page

Python Program To Find H.C.F of Two Numbers

This Python program defines a function to find the highest common factor (HCF) of two numbers. It takes in two numbers as arguments, chooses the smaller number, and uses a for loop to find the largest integer that divides both numbers.

Uploaded by

local drive
Copyright
© © All Rights Reserved
We take content rights seriously. If you suspect this is your content, claim it here.
Available Formats
Download as DOCX, PDF, TXT or read online on Scribd
0% found this document useful (0 votes)
40 views1 page

Python Program To Find H.C.F of Two Numbers

This Python program defines a function to find the highest common factor (HCF) of two numbers. It takes in two numbers as arguments, chooses the smaller number, and uses a for loop to find the largest integer that divides both numbers.

Uploaded by

local drive
Copyright
© © All Rights Reserved
We take content rights seriously. If you suspect this is your content, claim it here.
Available Formats
Download as DOCX, PDF, TXT or read online on Scribd
You are on page 1/ 1

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

You might also like