Jump to content

Sum and product of an array: Difference between revisions

(→‎{{header|Raven}}: Added REBOL example.)
Line 397:
<lang logo>print apply "sum arraytolist {1 2 3 4 5}
print apply "product arraytolist {1 2 3 4 5}</lang>
=={{header|Lua}}==
<lang lua>
function sumf(a, ...) return a and a + sumf(...) or 0 end
function sumt(t) return sumf(unpack(t)) end
function prodf(a, ...) return a and a * prodf(...) or 1 end
function prodt(t) return prodf(unpack(t)) end
 
print(sumt{1, 2, 3, 4, 5})
print(prodt{1, 2, 3, 4, 5})</lang>
 
=={{header|Lucid}}==
prints a running sum and product of sequence 1,2,3...
Anonymous user
Cookies help us deliver our services. By using our services, you agree to our use of cookies.