Anonymous user
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)*/
do j=1 for
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
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'
say 'product of'
/*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>
|