Learn about Find GCD of Two Numbers using Recursion Python in the below code example. Also, refer to the comments in the code snippet to get a detailed view about what’s actually happening.
Program to Find GCD of Two Numbers using Recursion Python
The below code snippet finds the gcd of the two numbers given by the user. The recursive function
recur_gcd() takes two numbers and returns the GCD of the two numbers.
# Python program to find GCD of two numbers using recursion # recursive function def recur_gcd(x, y): if(y == 0): return x else: return recur_gcd(y, x%y) # inputs from user num1 = int(input('First Number: ')) num2 = int(input('Second Number: ')) # function call print('The GCD of',num1,'and',num2,'is',recur_gcd(num1, num2))
First Number: 36
Second Number: 54
The GCD of 36 and 54 is 18
Hope above code works for you and Refer the below Related Codes to gain more insights. Happy coding and come back again.
Similar Code : GCD Program in Python using Function