Sum and product of an array: Difference between revisions

Content added Content deleted
No edit summary
No edit summary
Line 1,185: Line 1,185:
product[a]
product[a]
</syntaxhighlight>
</syntaxhighlight>


=={{header|FutureBasic}}==
<syntaxhighlight lang="futurebasic">
local fn Sum( mutArr as CFMutableArrayRef ) as float
NSInteger i, count, value = 0
float sum = 0
count = fn ArrayCount( mutArr )
for i = 0 to count -1
value = fn NumberIntegerValue( fn ArrayObjectAtIndex( mutArr, i ) )
sum += value
next
end fn = sum


local fn Product( mutArr as CFMutableArrayRef ) as float
NSInteger i, count, value = 0
float prod = 0
count = fn ArrayCount( mutArr )
for i = 0 to count -1
value = fn NumberIntegerValue( fn ArrayObjectAtIndex( mutArr, i ) )
prod *= value
next
end fn = prod
</syntaxhighlight>



=={{header|Fōrmulæ}}==
=={{header|Fōrmulæ}}==
Line 1,215: Line 1,245:
The Product = 120
The Product = 120
</pre>
</pre>



=={{header|GAP}}==
=={{header|GAP}}==
Line 1,232: Line 1,263:
Product(v, n -> 1/n);
Product(v, n -> 1/n);
# 1/40320</syntaxhighlight>
# 1/40320</syntaxhighlight>




=={{header|GFA Basic}}==
=={{header|GFA Basic}}==
Line 1,252: Line 1,285:
PRINT "Product is ";product%
PRINT "Product is ";product%
</syntaxhighlight>
</syntaxhighlight>




=={{header|Go}}==
=={{header|Go}}==