{BEGIN: EUCLID.TXT 4 18-Dec-85 6 512 Textfile } PROGRAM Euclid; {This programs uses Euclid's method to determine the greatest common divisor of two integers. efg, 26 January 1985. See p. 12 of "Algorithms" by Robert Sedgewick. Sample Data: Input: 1128 1272 Output: 24 } VAR x,y: INTEGER; FUNCTION gcd(u,v: INTEGER): INTEGER; VAR t: INTEGER; BEGIN WHILE v <> 0 DO BEGIN t := u MOD v; u := v; v := t END; gcd := u // Use RESULT := u in Delphi (efg, Oct 2000) END {gcd}; BEGIN REPEAT WRITELN ('Enter two numbers (0s to quit): '); READLN (x,y); IF (ABS(x) > 0) AND (ABS(y) > 0) THEN WRITELN ('Greatest common divisor for ',x,' and ',y,' is ',gcd(x,y)) UNTIL (x = 0) OR (y = 0) END {Euclid}. {END: CS217:EUCLID.TEXT }