Sum and product of an array: Difference between revisions

m
→‎{{header|REXX}}: indented DO loops, changed '''output''' template, removed superfluous blank lines. -- ~~~~
m (→‎{{header|REXX}}: indented DO loops, changed '''output''' template, removed superfluous blank lines. -- ~~~~)
Line 1,307:
 
=={{header|REXX}}==
<lang rexx>/*REXX program to add and seperately multiply elements of an array. */
<lang rexx>
/*REXX program to add and seperately multiply elements of an array. */
 
numeric digits 30 /*allow 30-digit numbers (default is 9)*/
 
y.0=20 /*one method of indicating array size. */
do j=1 for y.0 /*build an array of twenty elements. */
 
do j=1 for y.0j=j /*buildset an1st arrayto of1, twenty3rd elements.to 3, 9th to 9 ... */
y.j=j end /*set 1st to 1, 3rd to 3, 9th to 9 ... j*/
end
 
 
 
 
 
sum=0 /*initialize SUM to zero. */
prod=1 /*initialize PROD to unity. */
do k=1 for y.0
 
sum =sum +y.k /*add the element to the running total.*/
do k=1 for y.0
sum =sum +y.k prod=prod*y.k /*addmultiple the element to the running totalprod.*/
prod=prod*y.k end /*multiple the element to running prod.k*/
end
 
say ' sum of' y.0 "elements for the Y array is:" sum
say 'product of' y.0 "elements for the Y array is:" prod</lang>
'''output'''
</lang>
<pre style="height:30ex;overflow:scroll">
Output:
<pre style="height:30ex;overflow:scroll">
sum of 20 elements for the Y array is: 210
product of 20 elements for the Y array is: 2432902008176640000