GCD of Two Numbers - Learn Engineering

All the news and updates relevant to Engineering. You can also Write a post here

Breaking

Friday, June 19, 2020

GCD of Two Numbers

python-mini

Question

To Print the GCD of two numbers.

Sample TestCaseExpected Output

Enter First number :  2                                                                                       GCD is  2

Enter Second number : 4

Answer


def gcd(a,b):
    if(b==0):
        return a
    else:
        return gcd(b,a%b)
a=int(input("Enter first number : "))
b=int(input("Enter second number : "))
GCD=gcd(a,b)
print("GCD is",GCD)

No comments:

Post a Comment