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
What do you understand by recursion ? State the advantages and disadvantages of using recursion.
Write a recursive function to add the first 'n' terms of the series:
1 + 1/2 - 1/3 + 1/4 - 1/5……………
Write a Python function to multiply all the numbers in a list.
Sample List: (8, 2, 3, -1, 7)
Expected Output : -336Write a Python function to calculate the factorial of a number (a non-negative integer). The function accepts the number whose factorial is to be calculated as the argument.