[ create a new paste ] login | about

Link: http://codepad.org/x8n2Lk8r    [ raw code | output | fork ]

OCaml, pasted on Jan 17:
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
let rec fact1 n =
  match n with
    0 -> 1
  | n -> n * fact2 (n - 1)
and fact2 n = 
  if n < 2 then 1 
           else n * fact3 (n - 1)
and fact3 = function
  | 0 -> 1 
  | n -> n * fact1 (n - 1);; 

print_int (fact1 5);;
print_string "\n";;
print_int (fact2 5);;
print_string "\n";;
print_int (fact3 5);;


Output:
1
2
3
120
120
120


Create a new paste based on this one


Comments: