Q:

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

0

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

All Answers

need an explanation for this answer? contact us directly to get an explanation for this answer

I have used python 3.7 compiler for debugging purpose.

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))

Result:

20

10

need an explanation for this answer? contact us directly to get an explanation for this answer

total answers (1)

This question belongs to these collections

Similar questions


need a help?


find thousands of online teachers now