Contact: aviboots(AT)netvision.net.il
39,959 questions
51,901 answers
573 users
import math a = 12 b = 20 gcd = math.gcd(a, b) print("The GCD (greatest common divisor) of ", a, " and ", b, " is: ", gcd) ''' run: The GCD (greatest common divisor) of 12 and 20 is: 4 '''
a = 12 b = 20 i = a if a < b else b while i <= a and i <= b: if a % i == 0 and b % i == 0: gcd = i break i -= 1 print("The GCD (greatest common divisor) of ", a, " and ", b, " is: ", gcd) ''' run: The GCD (greatest common divisor) of 12 and 20 is: 4 '''
def gcd(a, b): return a if b == 0 else gcd(b, a % b) x = 12 y = 20 print("The GCD (greatest common divisor) of ", x, " and ", y, " is: ", gcd(x, y)) ''' run: The GCD (greatest common divisor) of 12 and 20 is: 4 '''
a = 12 b = 20 i = 1 while i <= a and i <= b: if a % i == 0 and b % i == 0: gcd = i i += 1 print("The GCD (greatest common divisor) of ", a, " and ", b, " is: ", gcd) ''' run: The GCD (greatest common divisor) of 12 and 20 is: 4 '''
import numpy as np a = 12 b = 20 gcd = np.gcd(a, b) print("The GCD (greatest common divisor) of ", a, " and ", b, " is: ", gcd) ''' run: The GCD (greatest common divisor) of 12 and 20 is: 4 '''