def GCD(x, y): # The greatest common denominator (GCD) is the largest positive integer # that divides into both numbers without a remainder. # Examples: GCD(256,64)=64, GCD(12,8)=4, GCD(5,3)=1 # Work With absolute values (positive integers) if x < 0 : x = -x if y < 0 : y = -y if x + y > 0 : g = y # Iterate Until x = 0 while x > 0: g = x x = y % x y = g return g else: # Error, both parameters zero return 0
Hide code
Visustin flow chart for Python