Sum and product of an array: Difference between revisions
Sum and product of an array en True BASIC
(Sum and product of an array en QBasic) |
(Sum and product of an array en True BASIC) |
||
Line 2,774:
<lang trith>[1 2 3 4 5] 0 [+] foldl</lang>
<lang trith>[1 2 3 4 5] 1 [*] foldl</lang>
=={{header|True BASIC}}==
{{works with|QBasic}}
<lang QBasic>DIM array(1 TO 5)
DATA 1, 2, 3, 4, 5
FOR index = LBOUND(array) TO UBOUND(array)
READ array(index)
NEXT index
LET sum = 0
LET prod = 1
FOR index = LBOUND(array) TO UBOUND(array)
LET sum = sum + array(index)
LET prod = prod * array(index)
NEXT index
PRINT "The sum is "; sum
PRINT "and the product is "; prod
END</lang>
=={{header|TUSCRIPT}}==
|