Tech Study

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

Introduction

Write a Python program to compute the greatest common divisor (GCD). 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

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

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

Python Examples

Introduction: Python Examples are the basic programming concepts of python like python syntax,python data types,,python operators,python if else,python comments etc.. …

Read more

C String Functions

C String Functions perform certain operations, It provides many useful string functions which can come into action. The <string.h> header …

Read more