Aim:

To write a Python program to find GCD of two numbers.

Algorithm:

1. Define a function named compute GCD()

2. Find the smallest among the two inputs x and y

3. Perform the following step till smaller+1

Check if ((x % i == 0) and (y % i == 0)), then assign GCD=i

4. Print the value of gcd

Program:

def computeGCD(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 = 54

num2 = 24

# take input from the user

# num1 = int(input("Enter first number: "))

# num2 = int(input("Enter second number: "))

print("The GCD. of", num1,"and", num2,"is", computeGCD(num1, num2))

Sample Output:

 $python main.py ('The GCD. of', 54, 'and', 24, 'is', 6)