Testing a progam

Hi, I’m a beginner and new here i have this small code that searches for the PGCD but i couldn’t test the program here is the code i wrote:

let rec pgcd a b =
  if b = 0 then a else pgcd b (a mod b)

let res = pgcd 10 5 

let test ()= Printf.printf "%d" res

but i can’t see the result

You only defined a test function, you need to invoke it for example with:

let () = test ()
1 Like

Also you probably need a newline: "%d\n"

It’s a good idea but standard channels are automatically flushed when the program exits, so formally you don’t need it. Also if you really want to flush the channel it’s rather "%d%!" that you want to write.

1 Like