A Program to Find GCD
In this example, we are giving a program to find GCD(greatest common divisor).
Program to find GCD:
# Find GCDdef compute_gcd(x, y):if x > y:smaller = yelse:smaller = xfor i in range(1, smaller+1):if ((x % i == 0) and (y % i == 0)):gcd = ireturn gcdnum1 = 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