HCF of n numbers in python by R4R Team

- stands for Highest common factor

Example -

HCF of 8 and 12 is 4
HCF of 13,17,11 and 31 is 1
HCF of 100,200 and 300 is 100
HCF of 8,12,20,42 and 54 is 2

program -

def check(l,n):
for i in l:
if i%n!=0:
return 0
return 1

print("Enter numbers to find the HCF")
if check(l,m):
print("HCF is - "+str(m))

output -

Enter numbers to find the HCF
13 17 11 31
HCF is - 1

Enter numbers to find the HCF
8 12 20 42
HCF is - 2

-In this program, check() function is check the number is common factor or not.
- we create a list of input numbers and find the minimum out of them then decrease value one by one and for each value we check that it is hcf or not.

Leave a Comment:
R4R Team
R4Rin Top Tutorials are Core Java,Hibernate ,Spring,Sturts.The content on R4R.in website is done by expert team not only with the help of books but along with the strong professional knowledge in all context like coding,designing, marketing,etc!