Write a Python program to compute the greatest common divisor (GCD)

code:-

def gcd(a, b):
    gcd = 1
 
    if a % b == 0:
        return y
 
    for k in range(int(b / 2), 0, -1):
        if a % k == 0 and b % k == 0:
            gcd = k
            break  
    return gcd
 
print(gcd(20, 60))
print(gcd(10, 40))

output:-
20
10
>>> 

Post a Comment

If you have any doubts, Please let me know
Thanks!

Previous Post Next Post