Coprimes: Difference between revisions

Content added Content deleted
m (syntax highlighting fixup automation)
(add OCaml)
Line 820: Line 820:
18 and 29 are coprimes.
18 and 29 are coprimes.
60 and 15 are not coprimes.</pre>
60 and 15 are not coprimes.</pre>

=={{header|OCaml}}==
<syntaxhighlight lang="ocaml">let rec is_coprime a = function
| 0 -> a = 1
| b -> is_coprime b (a mod b)

let () =
let p (a, b) =
Printf.printf "%u and %u are%s coprime\n" a b (if is_coprime a b then "" else " not")
in
List.iter p [21, 15; 17, 23; 36, 12; 18, 29; 60, 15]</syntaxhighlight>
{{out}}
<pre>
21 and 15 are not coprime
17 and 23 are coprime
36 and 12 are not coprime
18 and 29 are coprime
60 and 15 are not coprime
</pre>


=={{header|Perl}}==
=={{header|Perl}}==