19 lines
407 B
OCaml
19 lines
407 B
OCaml
(* File gcd.ml *)
|
|
let rec gcd a b =
|
|
if b = 0 then a
|
|
else gcd b (a mod b);;
|
|
|
|
let main () =
|
|
let len = Array.length Sys.argv in
|
|
Printf.printf "array length %d\n" len;
|
|
if len < 3 then (
|
|
Printf.printf "must have 2 args";
|
|
exit 0;
|
|
);
|
|
let a = int_of_string Sys.argv.(1) in
|
|
let b = int_of_string Sys.argv.(2) in
|
|
Printf.printf "gcd of %d and %d is %d\n" a b (gcd a b);
|
|
exit 0;;
|
|
main ();;
|
|
|