Sum and product of an array: Difference between revisions
Content added Content deleted
(Add lang example) |
No edit summary |
||
Line 3,043: | Line 3,043: | ||
Prod: 120 |
Prod: 120 |
||
</pre> |
</pre> |
||
=={{header|SparForte}}== |
|||
As a structured script. |
|||
<syntaxhighlight lang="ada">#!/usr/local/bin/spar |
|||
pragma annotate( summary, "arraysum" ) |
|||
@( description, "Compute the sum and product of an array of integers." ) |
|||
@( see_also, "http://rosettacode.org/wiki/Sum_and_product_of_an_array" ) |
|||
@( author, "Ken O. Burtch" ); |
|||
pragma license( unrestricted ); |
|||
pragma restriction( no_external_commands ); |
|||
procedure arraysum is |
|||
type int_array is array(1..10) of integer; |
|||
myarr : int_array := (1,2,3,4,5,6,7,8,9,10 ); |
|||
begin |
|||
? stats.sum( myarr ); |
|||
declare |
|||
product : integer := 1; |
|||
begin |
|||
for i in arrays.first( myarr )..arrays.last( myarr ) loop |
|||
product := @ * myarr(i); |
|||
end loop; |
|||
? product; |
|||
end; |
|||
end arraysum;</syntaxhighlight> |
|||
=={{header|Sparkling}}== |
=={{header|Sparkling}}== |