Q. Write recursive code to compute the greatest common divisor of two numbers.


Answer =

def gcd (a,b):
    if b == 0 :
        return a
    else:
        return gcd (b, a % b)
    
N1 = int(input("Enter first number:"))
N2 = int(input ("Enter second number:"))
D = gcd(N1, N2)
print("GCD of", N1, "and", N2, "is:", D)


Post a Comment

You can help us by Clicking on ads. ^_^
Please do not send spam comment : )

Previous Post Next Post