Sum and product of an array: Difference between revisions

m
→‎{{header|REXX}}: added whitespace, simplified variable name for the number of numbers. -- ~~~~
m (→‎{{header|REXX}}: added a comment, corrected a misspelling. -- ~~~~)
m (→‎{{header|REXX}}: added whitespace, simplified variable name for the number of numbers. -- ~~~~)
Line 1,320:
numeric digits 30 /*allow 30-digit numbers (default is 9)*/
 
y.0m=20 /*one method of indicating array size. */
do j=1 for y.0m /*build an array of twenty elements. */
y.j=j /*set 1st to 1, 3rd to 3, 9th to 9 ... */
end /*j*/
sum=0 /*initialize SUM to zero. */
prod=1 /*initialize PROD to unity. */
do k=1 for y.0m
sum =sum +y.k /*add the element to the running total.*/
prod=prod*y.k /*multiple the element to running prod.*/
end /*k*/
 
say ' sum of' y.0 m "elements for the Y array is: " sum
say 'product of' y.0 m "elements for the Y array is: " prod
 
/*stick a fork in it, we're done. */</lang>
'''output'''
<pre style="overflow:scroll">
sum of 20 elements for the Y array is: 210
product of 20 elements for the Y array is: 2432902008176640000
</pre>