feat: add sample gcd
This commit is contained in:
18
gcd.ml
Normal file
18
gcd.ml
Normal file
@@ -0,0 +1,18 @@
|
||||
(* 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 ();;
|
||||
|
||||
Reference in New Issue
Block a user