Sum multiples of 3 and 5: Difference between revisions

(→‎{{header|Wren}}: Added GMP version.)
Line 2,891:
{{out}}
<pre>233168</pre>
=== Functional programming version (more idiomatic) ===
<lang ocaml>
open Printf;;
 
let sum_mults n =
let rec countem n sum =
match n with
| 0 -> sum
| _ -> countem (n - 1) (sum + if (n mod 5) = 0 || (n mod 3) = 0 then n else 0)
in
countem n 0;;
 
printf "The sum of the multiples of 3 or 5 below 1000 is %d\n" (sum_mults 999);;
</lang>
{{Out}}
<pre>
The sum of the multiples of 3 or 5 below 1000 is 233168
</pre>
 
=={{header|Oforth}}==
357

edits