Find GCD of two numbers | Using recursive function | Python Program
GCD (Greatest Common Divisor) :
The GCD (Greatest Common Divisor) of two or more integers, which are not all zero, is the largest positive integer that divides each of the integers. GCD is also known as GCF (Greatest Common Factor). For example, the GCD or GCF of 8 and 12 is 4.
Now, Here is a program written in Python language which tells you the GCD or GCF of any two positive integer numbers.
Code :
def gcd(a,b):
if a==b:
return a
elif a%b==0:
return b
elif b%a==0:
return a
elif a>b:
return gcd(a%b,b)
else:
return gcd(a,b%a)
num = input('Enter two numbers with a space in between : ').split(" ")
result=gcd(int(num[0]),int(num[1]))
print('The gcd is '+str(result))
Output :
If you have any question regarding this program, please ask in the comment section below.
---------------------------------------------------------------------------------------------------------------
---------------------------------------------------------------------------------------------------------------
ADS BY AMAZON.IN
Comments
Post a Comment
Give your feedback!
DO NOT SPAM !!
NO THIRD PARTY PROMOTIONAL LINK !!!! (else comment will be deleted.)