27
Question Write a program to find the greatest common divisor between two numbers.
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)Enter the first number: 24
Enter the second number: 6
The greatest common divisor of 24 and 6 is 6
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