Python OOPs


Python SQLite


Examples


Others


HCF of GCD of Two Numbers using Python


Write a Python program to find HCF(Highest Common Factor) or GCD(Greatest Common Divisor) of two numbers.

n1=int(input("Enter Number 1 : "))
n2=int(input("Enter Number 2 : "))
m=min(n1,n2)
hcf=1
for i in range(1,m):
    if n1%i==0 and n2%i==0:
        hcf=i
print("HCF of {} and {} is {}".format(n1,n2,hcf))
Output:
Enter Number 1 : 60
Enter Number 2 : 30
HCF of 60 and 30 is 15