Sum and product of an array: Difference between revisions
→{{header|langur}}
Langurmonkey (talk | contribs) |
|||
(7 intermediate revisions by 6 users not shown) | |||
Line 934:
{{Out}}
<pre>77.9699690</pre>
=={{header|Bruijn}}==
:import std/List .
:import std/Math .
arr (+1) : ((+2) : ((+3) : {}(+4)))
main [∑arr : ∏arr]
</syntaxhighlight>▼
=={{header|C}}==
Line 1,373 ⟶ 1,383:
=={{header|Euler}}==
In Euler, a list must be assigned to a variable in order for it to be subscripted.
'''begin'''▼
▲<syntaxhighlight lang="euler">
'''new''' sumAndProduct;▼
▲begin
'''new''' sumField; '''new''' productField;▼
▲ new sumAndProduct;
sumAndProduct▼
▲ new sumField; new productField;
<- ` '''formal''' array;
▲ sumAndProduct
'''new''' sum; '''new''' product; '''new''' i; '''new''' v; '''label''' arrayLoop;
arrayLoop: '''if''' [ i
'''end''' '''else'''
'''new''' sp;▼
sp <- sumAndProduct( ( 1, 2, 3, 4, 5, 6, 7, 8, 9, 10 ) );
▲ new sp;
'''out''' sp[
'''end'''▼
'''end''' $▼
▲ end
▲end $
▲</syntaxhighlight>
=={{header|Euphoria}}==
Line 1,576 ⟶ 1,584:
=={{header|FutureBasic}}==
Traditional
<syntaxhighlight lang="futurebasic">
local fn Sum( mutArr as CFMutableArrayRef ) as float
Line 1,602 ⟶ 1,611:
end fn = prod
</syntaxhighlight>
Sum of array elements with key-value coding
local fn NumericalArraySum( array as CFArrayRef ) as CFNumberRef
end fn = fn ObjectValueForKeyPath( array, @"@sum.self" )
printf @"%@", fn NumericalArraySum( @[@0.0454, @-1.3534, @0.345, @65, @-0.345, @1.35] )
HandleEvents
</syntaxhighlight>
{{output}}
<pre>
65.042
</pre>
=={{header|Fōrmulæ}}==
{{FormulaeEntry|page=https://formulae.org/?script=examples/Sum_and_product_of_an_array}}
'''Solution'''
[[File:Fōrmulæ - Sum and product of an array 01.png]]
'''Test cases'''
[[File:Fōrmulæ - Sum and product of an array 02.png]]
[[File:Fōrmulæ - Sum and product of an array 03.png]]
[[File:Fōrmulæ - Sum and product of an array 04.png]]
[[File:Fōrmulæ - Sum and product of an array 05.png]]
[[File:Fōrmulæ - Sum and product of an array 06.png]]
[[File:Fōrmulæ - Sum and product of an array 07.png]]
[[Wp:Empty sum|Empty sum]] and [[Wp:Empty_product|empty product]]:
[[File:Fōrmulæ - Sum and product of an array 08.png]]
[[File:Fōrmulæ - Sum and product of an array 09.png]]
=={{header|Gambas}}==
Line 2,033 ⟶ 2,083:
=={{header|langur}}==
<syntaxhighlight lang="langur">val .
writeln "
writeln " sum: ", fold
writeln "product: ", fold
</syntaxhighlight>
▲<syntaxhighlight lang="langur">val .arr = series 19
{{out}}
<pre>
sum: 190
product: 121645100408832000</pre>
Line 3,692 ⟶ 3,737:
=={{header|Wren}}==
{{libheader|Wren-math}}
<syntaxhighlight lang="
var a = [7, 10, 2, 4, 6, 1, 8, 3, 9, 5]
System.print("Array : %(a)")
|