Jump to content

Sum and product of an array: Difference between revisions

Added FreeBASIC
(Use reduce instead of fold)
(Added FreeBASIC)
Line 854:
sresult = sum(a);
presult = product(a);</lang>
 
=={{header|FreeBASIC}}==
<lang freebasic>' FB 1.05.0 Win64
 
Dim a(1 To 4) As Integer = {1, 4, 6, 3}
Dim As Integer i, sum = 0, prod = 1
For i = 1 To 4
sum += a(i)
prod *= a(i)
Next
Print "Sum ="; sum
Print "Product ="; prod
Print
Print "Press any key to quit"Sleep
</lang>
 
{{out}}
<pre>
Sum = 14
Product = 72
</pre>
 
=={{header|Frink}}==
9,490

edits

Cookies help us deliver our services. By using our services, you agree to our use of cookies.