Jump to content

Greatest common divisor: Difference between revisions

no edit summary
m (→‎Built-in: minor correction (->asList is deprecated; use '...' instead))
No edit summary
Line 1,923:
GCD(49865, 69811): 9973 (binary)</pre>
 
=={{header|Oberon-2}}==
Works with oo2c version 2
<lang oberon2>
MODULE GCD;
(* Greatest Common Divisor *)
IMPORT
Out;
PROCEDURE Gcd(a,b: LONGINT):LONGINT;
VAR
r: LONGINT;
BEGIN
LOOP
r := a MOD b;
IF r = 0 THEN RETURN b END;
a := b;b := r
END
END Gcd;
BEGIN
Out.String("GCD of 12 and 8 : ");Out.LongInt(Gcd(12,8),4);Out.Ln;
Out.String("GCD of 100 and 5 : ");Out.LongInt(Gcd(100,5),4);Out.Ln;
Out.String("GCD of 7 and 23 : ");Out.LongInt(Gcd(7,23),4);Out.Ln;
Out.String("GCD of 24 and -112 : ");Out.LongInt(Gcd(12,8),4);Out.Ln;
Out.String("GCD of 40902 and 24140 : ");Out.LongInt(Gcd(40902,24140),4);Out.Ln
END GCD.
</lang>
Output:<br/>
<pre>
GCD of 12 and 8 : 4
GCD of 100 and 5 : 5
GCD of 7 and 23 : 1
GCD of 24 and -112 : 4
GCD of 40902 and 24140 : 34
</pre>
=={{header|Objeck}}==
<lang objeck>
Anonymous user
Cookies help us deliver our services. By using our services, you agree to our use of cookies.