Sum and product of an array: Difference between revisions
Content added Content deleted
m (→{{header|REXX}}: indented DO loops, changed '''output''' template, removed superfluous blank lines. -- ~~~~) |
|||
Line 1,307: | Line 1,307: | ||
=={{header|REXX}}== |
=={{header|REXX}}== |
||
⚫ | |||
<lang rexx> |
|||
⚫ | |||
numeric digits 30 /*allow 30-digit numbers (default is 9)*/ |
numeric digits 30 /*allow 30-digit numbers (default is 9)*/ |
||
y.0=20 /*one method of indicating array size. */ |
y.0=20 /*one method of indicating array size. */ |
||
do j=1 for y.0 /*build an array of twenty elements. */ |
|||
y.j=j /*set 1st to 1, 3rd to 3, 9th to 9 ... */ |
|||
end /*j*/ |
|||
end |
|||
sum=0 /*initialize SUM to zero. */ |
sum=0 /*initialize SUM to zero. */ |
||
prod=1 /*initialize PROD to unity. */ |
prod=1 /*initialize PROD to unity. */ |
||
⚫ | |||
sum =sum +y.k /*add the element to the running total.*/ |
|||
⚫ | |||
prod=prod*y.k /*multiple the element to running prod.*/ |
|||
end /*k*/ |
|||
end |
|||
say ' sum of' y.0 "elements for the Y array is:" sum |
say ' sum of' y.0 "elements for the Y array is:" sum |
||
say 'product of' y.0 "elements for the Y array is:" prod |
say 'product of' y.0 "elements for the Y array is:" prod</lang> |
||
'''output''' |
|||
</lang> |
|||
⚫ | |||
Output: |
|||
⚫ | |||
sum of 20 elements for the Y array is: 210 |
sum of 20 elements for the Y array is: 210 |
||
product of 20 elements for the Y array is: 2432902008176640000 |
product of 20 elements for the Y array is: 2432902008176640000 |