Jump to content

Sum and product of an array: Difference between revisions

→‎{{header|APL}}: Added a solution with the pair primitive function in dzaima/APL and Extended Dyalog APL
(→‎{{header|APL}}: Added a solution with the pair primitive function in dzaima/APL and Extended Dyalog APL)
Line 260:
=={{header|APL}}==
{{works with|APL2}}
<lang apl> sum ← +/ ⍝ sum (+) over (/) an array
prod ← ×/ ⍝ product (×) over (/) an array
lista ← 1 2 3 4 5 ⍝ assign a literal array to variable 'a'
sum lista
15
prod lista
120</lang>
What follows ⍝ is a comment and / is usually known as ''reduce'' in APL.
 
{{works with|dzaima/APL}}
{{works with|Extended Dyalog APL}}
using the [https://aplwiki.com/wiki/Pair pair (⍮)] primitive function ([https://tio.run/##SyzI0U2pSszMTfz//1Hf1EdtEzS09R/1rjs8XV/TUMFIwVjBRMH0/38A try it online])
<lang apl> ⎕ ← (+/ ⍮ ×/) 1 2 3 4 5
15 120</lang>
 
=={{header|AppleScript}}==
Anonymous user
Cookies help us deliver our services. By using our services, you agree to our use of cookies.