HCF of two number in python by R4R Team

HCF-
- stands for Highest common factor

Example -

HCF of 8 and 12 is 4
HCF of 13 and 17 is 1
HCF of 100 and 200 is 100
HCF of 15 and 50 is 5

Program -

print("Enter first number")
a=int(input())
print("Enter second number")
b=int(input())
m=min(a,b)
while(1):
if a%m==0 and b%m==0:
print("HCF is - "+str(m))
break
m=m-1


output -

Enter first number
13
Enter second number
17
HCF is - 1

Enter first number
100
Enter second number
200
HCF is - 100

Enter first number
8
Enter second number
12
HCF is - 4

-In this program, we take mininum out of two number and decrease one by one and for each value we check that it divide the given inputs or not.



Leave a Comment:
Search
Categories
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!