In python, create a well documented program that uses the Euclidean Algorithm to compute the greatest common divisor of two integers a and b.
def gcd(n1, n2): while n2 != 0: # as long as second number is not 0 temp = n1 # back up n1 in temp n1 = n2 # set n1 to n2 n2 = temp % n2 # set remainder of n1 when divided with n2 in n2 return n1 # return final value of n2 n1 = int(input("Enter first number: ")) n2 = int(input("Enter second number: ")) print("GCD({}, {}) is {}".format(n1, n2, gcd(n1, n2)))
Get Answers For Free
Most questions answered within 1 hours.