Jump to content

Sum and product of an array: Difference between revisions

Add Nimrod
(added swift)
(Add Nimrod)
Line 1,150:
= 6</lang>
(All these notations are equivalent)
 
=={{header|Nimrod}}==
<lang nimrod>var xs = @[1,2,3,4,5,6]
 
var sum, product: int
 
for x in xs:
sum += x
product *= x</lang>
 
Or functionally:
<lang nimrod>import sequtils
 
let
xs = @[1,2,3,4,5,6]
sum = xs.foldl(a + b)
product = xs.foldl(a * b)</lang>
 
=={{header|Objeck}}==
Anonymous user
Cookies help us deliver our services. By using our services, you agree to our use of cookies.