Sum and product of an array: Difference between revisions
Content deleted Content added
m Some formatting. Replaced sequences with arrays to simplify. |
|||
Line 1,792: | Line 1,792: | ||
=={{header|Nim}}== |
=={{header|Nim}}== |
||
<lang nim>var xs = |
<lang nim>var xs = [1, 2, 3, 4, 5, 6] |
||
var sum, product: int |
var sum, product: int |
||
Line 1,806: | Line 1,806: | ||
let |
let |
||
xs = |
xs = [1, 2, 3, 4, 5, 6] |
||
sum = xs.foldl(a + b) |
sum = xs.foldl(a + b) |
||
product = xs.foldl(a * b)</lang> |
product = xs.foldl(a * b)</lang> |
||
Line 1,813: | Line 1,813: | ||
<lang nim>import math |
<lang nim>import math |
||
let numbers = |
let numbers = [1, 5, 4] |
||
let total = sum(numbers) |
let total = sum(numbers) |
||