eval.in

Paste #49624

OCaml — OCaml 4.00.1, pasted 3 years ago

 1
 2
 3
 4
 5
 6
 7
 8
 9
10
11
let fib n =
  let a, b = ref 0, ref 1 in
  for i = 0 to n - 1 do
    let c = !a + !b in
    b := !a;
    a := c
  done;
  !a

let _ =
  print_int (fib 30)

Program Output

832040

OK (0.012 sec real, 0.012 sec wall, 6 MB, 9 syscalls)

Fork