print_int ;; print_float ;; print_char ;; print_string ;; print_newline ;; read_int ;; read_float ;; read_line ;; (* Code Ocaml 0*) let dialogue () = print_string "Quel est votre prénom ? "; print_newline () ; let reponse = read_line () in print_string ("Bonjour " ^ reponse) ; print_newline () ;; dialogue () ;; (* Code Ocaml 2*) let x = ref 0 ;; x := 2 ;; x := !x + 3 ;; !x ;; x ;; (* Code Ocaml 3*) let a = 1 ;; let incr x = x + a ;; let a = 2 ;; incr 0 ;; (* Code Ocaml 4*) let a = ref 1 ;; let incr x = x + !a ;; a := 2 ;; incr 0 ;; (* Code Ocaml 5*) let x = ref 0 ;; let y = ref 0 ;; !x = !y ;; !x == !y ;; x = y ;; x == y ;; (* Code Ocaml 6*) let z = x ;; z == x ;; x := 1 ;; !z ;; (* Code Ocaml 7*) let x = if true then 1 else 2 ;; let x = if true then 1 else 2. ;; (* Code Ocaml 8*) if true then 1 ;; if true then print_int 1 ;; (* Code Ocaml 9*) for i = 10 downto 1 do print_int i ; print_char ' ' done ;; (* Code Ocaml 10*) let t = [|'c'; 'a'; 'm'; 'l'|] and u = Array.make 5 1 ;; (* Code Ocaml 11*) u.(1) <- 2 ;; u.(2) <- u.(1) + 1 ;; u ;; (* Code Ocaml 12*) Array.length u ;; (* Code Ocaml 13*) let max_array t = let n = Array.length t in if n = 0 then failwith "Tableau vide !" else let maxi = ref t.(0) in for i = 1 to n - 1 do maxi := max !maxi t.(i) done ; !maxi ;; max_array [|1; 3; 4; 5; 1; -8; 3 ;4 ;5 ;5 ;1; 0 |] ;; (* Code Ocaml 14*) let cherche prop t = let trouve = ref false and i = ref 0 and n = Array.length t in while not !trouve && !i < n do trouve := prop t.(!i); i := !i + 1; done ; !trouve ;; let plusgrand6 x = x >= 6 ;; cherche plusgrand6 [|1; 3; 4; 5; 1; -8; 3 ;4 ;5 ;5 ;1; 0 |] ;; cherche plusgrand6 [|1; 3; 4; 5; 1; 8; 3 ;4 ;5 ;5 ;1; 0 |] ;; (* Code Ocaml 15*) let max_array t = let rec aux i = match i with | i when i < 0 -> failwith "Tableau vide" | i when i = 0 -> t.(0) | i -> max t.(i) (aux (i - 1)) in aux (Array.length t - 1) ;; max_array [|1; 3; 4; 5; 1; -8; 3 ;4 ;5 ;5 ;1; 0 |] ;; (* Code Ocaml 16*) let cherche prop t = let rec aux i = match i with | i when i < 0 -> false | i -> prop t.(i) || aux (i -1) in aux (Array.length t - 1) ;; (* Code Ocaml 18 et 19*) let m = Array.make 3 (Array.make 2 0) ;; m.(0).(0) <-1 ;; m ;; (* Code Ocaml 20*) let m = Array.make 3 [||] ;; for i = 0 to 2 do m.(i) <- Array.make 2 0 done ;; m.(0).(0) <-1 ;; m ;; (* Code Ocaml 21*) let m = Array.make_matrix 3 2 0;; m.(0).(0) <-1 ;; m ;; (* Code Ocaml 22*) let s1 = "abc" ;; s1.[1] ;; s1.[1] <- 'j' ;; let s2 = String.make 5 'a' ;; String.length s2 ;;