Advertisement
Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- (* exo 3 *)
- let shift_left(x, y, z : int ref * int ref * int ref) : unit =
- let a : int = !x in
- (
- x := !y ;
- y := !z ;
- z := a
- )
- ;;
- let shift_right(x, y, z : int ref * int ref * int ref) : unit =
- let a : int = !z in
- (
- z := !y ;
- y := !x ;
- x := a
- )
- ;;
- (* exo 5 *)
- let rec print_list(m : int list) : unit =
- if m = []
- then print_newline()
- else
- (
- print_int(fst(m)) ;
- print_string("––-");
- print_list(rem_fst(m))
- )
- ;;
- (* exo 6 *)
- let rec starline_aux(k : int) : unit =
- if k = 0
- then print_newline()
- else
- (
- print_char(’*’) ;
- starline_aux(k-1)
- )
- ;;
- let starline(k : int) : unit =
- if k < 0
- then failwith "erreur starline : parametre negatif"
- else starline_aux(k)
- ;;
- let getprintnameage() : unit =
- let forename : string ref = ref " "
- and age : string ref = ref " "
- and len : int ref = ref 0 in
- (
- print_string("quel est votre prenom ?") ;
- print_newline() ;
- forename := read_line() ;
- print_string("quel est votre age ?") ;
- print_newline() ;
- age := string_of_int(read_int()) ;
- len := 6 + String.length(!forename) + String.length(!age) ;
- starline(!len) ;
- print_string("* ") ;
- print_string(!forename) ;
- print_string(", ") ;
- print_string(!age) ;
- print_string(" *") ;
- print_newline() ;
- starline(!len)
- )
- ;;
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement