Question:Write a python program to find the HCF

**Program:**

1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 |
#Program to find the H.C.F of two input number def HCF(x, y): # choose the smaller number if x > y: small = y else: small = x for i in range(1, small+1): if((x % i == 0) and (y % i == 0)): hcf = i return hcf n1 = int(input("Enter first number: ")) n2 = int(input("Enter second number: ")) print "The H.C.F. of", n1,"and", n2,"is",HCF(n1, n2) |

**Explanation:**

The Highest Common Factor (**H.C.F**) of two (or more) numbers is the largest number that divides evenly into both numbers. In other words the **H.C.F** is the largest of all the common factors. The common factors or of 12 and 18 are 1, 2, 3 and 6. The largest common factor is 6, so this is the **H.C.F.** of 12 and 18.

**Output:**

1 2 3 4 5 |
Enter first number: 10 Enter second number: 5 The H.C.F. of 10 and 5 is 5 |

Do share your feedback in comments to help us adding more programs like this.

## Leave a Reply