Python program to compute the gcd of two numbers
Here you will get an example to write a Python program to compute the gcd of two numbers.
Example of python program to compute the gcd of two numbers
1 2 3 4 5 6 7 8 9 10 | def gcd_recursive(a, b): if b == 0: return a return gcd_recursive(b, a % b) num1 = int(input("Enter the first number: ")) num2 = int(input("Enter the second number: ")) gcd = gcd_recursive(num1, num2) print(f"GCD of {num1} and {num2} is {gcd}") |
Output
Enter the first number: 12
Enter the second number: 16
GCD of 12 and 16 is 4
Check out our other Python programming examples