Procedure.l GCD(x.l, y.l) ; 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 g.l ; Work With absolute values (positive integers) If x < 0 : x = -x : EndIf If y < 0 : y = -y : EndIf If x + y > 0 g = y ; Iterate Until x = 0 While x > 0 g = x x = y % x y = g Wend ProcedureReturn g Else ; Error, both parameters zero ProcedureReturn 0 EndIf EndProcedure
Hide code
Visustin flow chart for PureBasic