GCD Using While Loop In Python

   

   GCD Using While Loop In Python 

The HCF or GCD of two integers is the largest integer that can exactly divide both numbers (without a remainder).

GCD: greatest common divisor 


Program:

n1=int(input("Enter n1 integer: "))
n2=int(input("Enter n2 integer: "))       
    
while(n1!=n2):

        if(n1 > n2):
            n1 -= n2;
        else:
            n2 -= n1;

print("GCD = ",n1);


OutPut:
Enter n1 integer: 81
Enter 21 integer: 153
GCD =  9








No comments:

Post a Comment