Python GCD Recursive Function

By | December 4, 2022

Python GCD Recursive Function – Write a Python Program to find GCD of two numbers by recursion.

Python recursive function GCD

Python GCD Recursive Function

Python Program GCD of Two Numbers

# Write a Python Program to find GCD
# of two numbers using Recursion

# define a recursive GCD function
def recursive_gcd(a,b):
    if(b==0):
        return a
    else:
        return recursive_gcd(b,a%b)

# main
# input two integer numbers
a=int(input("Enter first number:"))
b=int(input("Enter second number:"))

# call recursive function
gcd=recursive_gcd(a,b)

# print GCD
print("GCD is: ", gcd)

Output

Enter first number:40
Enter second number:230
GCD is: 10

Python Program GCD of Two Numbers using Recursion

You will also like:

Python Recursion With Example Recursive Function 

Loading

Leave a Reply

Your email address will not be published. Required fields are marked *