Greatest common divisor: Difference between revisions

Content added Content deleted
m (→‎{{header|Phix}}: added syntax colouring the hard way)
Line 3,265: Line 3,265:
=={{header|Pascal}} / {{header|Delphi}} / {{header|Free Pascal}}==
=={{header|Pascal}} / {{header|Delphi}} / {{header|Free Pascal}}==
===Recursive Euclid algorithm===
===Recursive Euclid algorithm===
{{works with|Free Pascal|version 3.2.0 }}
<lang pascal>
<lang pascal>
PROGRAM EXRECURGCD.PAS;
{$mode objFPC}{R+}

(*
* Free Pascal Compiler version 3.2.0 [2020/06/14] for x86_64
* The free and readable alternative
* compiles natively to almost any platform, including raspberry PI *
*)

{$IFDEF FPC}
{$mode objfpc}{$H+}{$J-}{R+}
{$ELSE}
{$APPTYPE CONSOLE}
{$ENDIF}

FUNCTION gcd_recursive(u, v: longint): longint;
FUNCTION gcd_recursive(u, v: longint): longint;


BEGIN
BEGIN
IF v = 0 THEN EXIT( u );
IF v = 0 THEN EXIT( u );
result := gcd_recursive( v, u MOD v ) ;
result := gcd_recursive( v, u MOD v ) ;
END;
END;


BEGIN
</lang>

WriteLn ( gcd_recursive ( 231, 7 ) ) ;

END.

</lang>JPD 2021/03/14


===Iterative Euclid algorithm===
===Iterative Euclid algorithm===