open Printf (* Pour écrire « printf » directement *) let afficher_monome {coeff=c ; degre=d} = if c > 0 then printf "+" ; printf "%dX^%d" c d ;; let afficher p = match p with | [] -> printf "0" (* un cas particulier, quand même *) | _ -> List.iter afficher_monome p ;; |
(* fst indique le premier monôme (ne pas afficher le «+») *) let afficher_coeff fst c = if c > 0 && not fst then printf "+%d" c else printf "%d" c and afficher_puiss d = match d with | 1 -> printf "X" | _ -> printf "X^%d" d ;; let afficher_monome fst m = match m with | {degre=0} -> afficher_coeff fst m.coeff | {coeff=1} -> if not fst then printf "+" ; afficher_puiss m.degre | {coeff=-1} -> printf "-" ; afficher_puiss fst m.degre | _ -> afficher_coeff fst m.coeff ; afficher_puiss m.degre ;; |
let afficher p = match p with | [] -> printf "0" | m::rem -> afficher_monome true m ; List.iter (afficher_monmome false) rem ;; |
let rec do_afficher fst p = match p with | [] -> () | m::rem -> afficher_monome fst m ; do_afficher false rem ;; let afficher p = match p with | [] -> printf "0" | _ -> do_afficher true p ;; |