summaryrefslogtreecommitdiff
diff options
context:
space:
mode:
authorIgor Pashev <pashev.igor@gmail.com>2017-07-09 11:00:46 +0300
committerIgor Pashev <pashev.igor@gmail.com>2017-07-09 11:01:28 +0300
commit70135d54aafd032f94dfb4026d57a62d791d0706 (patch)
tree5bd5569784f045009fb9b13b96f82e0c66697f19
parent199541b289b2ad9a43e99f70446ad491d71d0337 (diff)
downloadgcd-70135d54aafd032f94dfb4026d57a62d791d0706.tar.gz
Update Pascal
-rw-r--r--gcd.pas80
1 files changed, 45 insertions, 35 deletions
diff --git a/gcd.pas b/gcd.pas
index 20a43f7..4253807 100644
--- a/gcd.pas
+++ b/gcd.pas
@@ -1,36 +1,46 @@
-{Tested with FreePascal 2.4.0}
-
-program GCD(output);
-uses sysutils; {StrToInt}
-
-function gcd2(a: integer; b: integer): integer;
-var c: integer;
-begin
- while b <> 0 do
- begin
- c := b;
- b := a mod b;
- a := c;
- end;
- gcd2 := a;
-end;
-
-function gcdn(n: array of integer): integer;
-var i: integer;
-begin
- gcdn := n[0];
- for i := 1 to High(n) do {See also <http://wiki.freepascal.org/for-in_loop> }
- gcdn := gcd2(gcdn, n[i]);
-end;
-
-
-var
- n: array of integer;
- i: integer;
-begin
- SetLength(n, ParamCount);
- for i := 1 to ParamCount do
- n[i-1] := StrToInt(ParamStr(i));
- Writeln(gcdn(n))
-end.
+{
+FreePascal: https://www.freepascal.org/
+Tested with FreePascal 2.4.0, 3.0.0
+Usage:
+
+ $ fpc gcd.pas -ogcd-pas
+ $ ./gcd-pas 44 55 66 121
+ 11
+
+}
+
+Program GCD(output);
+
+Uses sysutils; {StrToInt}
+
+Function gcd2(a: integer; b: integer): integer;
+Var c: integer;
+Begin
+ While b <> 0 Do
+ Begin
+ c := b;
+ b := a Mod b;
+ a := c;
+ End;
+ gcd2 := a;
+End;
+
+Function gcdn(n: Array Of integer): integer;
+Var i: integer;
+Begin
+ gcdn := n[0];
+ For i := 1 To High(n) Do {See also <http://wiki.freepascal.org/for-in_loop> }
+ gcdn := gcd2(gcdn, n[i]);
+End;
+
+
+Var
+ n: array Of integer;
+ i: integer;
+Begin
+ SetLength(n, ParamCount);
+ For i := 1 To ParamCount Do
+ n[i-1] := StrToInt(ParamStr(i));
+ Writeln(gcdn(n))
+End.