A Program to Find GCD
In this example, we are giving a program to find GCD(greatest common divisor).
Program to find GCD:
# Find GCD
def compute_gcd(x, y):
if x > y:
smaller = y
else:
smaller = x
for i in range(1, smaller+1):
if ((x % i == 0) and (y % i == 0)):
gcd = i
return gcd
num1 = int(input('Enter 1st number: '))
num2 = int(input('Enter 2nd number: '))
print("The G.C.D. is", compute_gcd(num1, num2))
Output:
Enter 1st number: 65 Enter 2nd number: 35 The G.C.D. is 5