Anonymous user
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. */▼
▲/*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. */
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
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'''
▲<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
|