KnowledgeBoat Logo

Computer Science

Write a program to find the greatest common divisor between two numbers.

Python

Python Functions

3 Likes

Answer

def gcd(a, b):
    while b:
        a, b = b, a % b
    return a

num1 = int(input("Enter the first number: "))
num2 = int(input("Enter the second number: "))
gcd_value = gcd(num1, num2)
print("The greatest common divisor of", num1, "and", num2, "is", gcd_value)

Output

Enter the first number: 24
Enter the second number: 6
The greatest common divisor of 24 and 6 is 6

Answered By

2 Likes


Related Questions