How to resolve the algorithm Sum and product of an array step by step in the SparForte programming language
Published on 12 May 2024 09:40 PM
How to resolve the algorithm Sum and product of an array step by step in the SparForte programming language
Table of Contents
Problem Statement
Compute the sum and product of an array of integers.
Let's start with the solution:
Step by Step solution about How to resolve the algorithm Sum and product of an array step by step in the SparForte programming language
Source code in the sparforte programming language
#!/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;
You may also check:How to resolve the algorithm Colour pinstripe/Display step by step in the Visual Basic .NET programming language
You may also check:How to resolve the algorithm Runge-Kutta method step by step in the C++ programming language
You may also check:How to resolve the algorithm Hough transform step by step in the Wren programming language
You may also check:How to resolve the algorithm Sum of squares step by step in the UNIX Shell programming language
You may also check:How to resolve the algorithm Run-length encoding step by step in the BASIC programming language