formations/algorithmique/cours/code/factorielle.ml

18 lines
241 B
OCaml
Raw Normal View History

2017-04-06 16:57:22 +02:00
let rec fact = function
|1 -> 1
| n -> n * fact (n-1) ;;
let print_fact n =
Printf.printf "factorielle %i = %i\n" n (fact n)
let main () =
begin
print_fact 5 ;
print_newline () ;
exit 0 ;
end
let _ = main ()