GCD of two numbers

# GCD of two numbers

num1 = int(input("Enter a number : "))
num2 = int(input("Enter a number : "))

if (num1 == 0 or num2 == 0):
    print("GCD of", num1,"and", num2 , "is 0")
else:
    tmp1, tmp2 = num1, num2

    while(tmp1 != tmp2):
        if (tmp1 > tmp2):
            tmp1 = tmp1 - tmp2
        else:
            tmp2 = tmp2 - tmp1
           
    print("GCD of", num1, "and", num2 , "is", tmp1)
   

No comments:

Post a Comment

Don't be a silent reader...
Leave your comments...

Anu