16 lines
388 B
OCaml
16 lines
388 B
OCaml
|
(* exercice 1 *)
|
||
|
let rec pgcd a b = match b with
|
||
|
| 0 -> a
|
||
|
# | _ -> pgcd (b) (a mod b);;
|
||
|
|
||
|
print_int (pgcd 12 6);;
|
||
|
|
||
|
(* exercice 2*)
|
||
|
let rec dichotomie func a b epsilon =
|
||
|
let c = (a+.b)/.2. in
|
||
|
if (b -. a) < epsilon then c
|
||
|
else if func(c) *. func(b) > 0. then dichotomie func c b epsilon
|
||
|
else dichotomie func a c epsilon;;
|
||
|
|
||
|
print_float (dichotomie sin 1. 4. 0.001);;
|