How to resolve the algorithm Sum and product of an array step by step in the ALGOL W 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 ALGOL W 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 ALGOL W programming language
Source code in the algol programming language
begin
% computes the sum and product of intArray %
% the results are returned in sum and product %
% the bounds of the array must be specified in lb and ub %
procedure sumAndProduct( integer array intArray ( * )
; integer value lb, ub
; integer result sum, product
) ;
begin
sum := 0;
product := 1;
for i := lb until ub
do begin
sum := sum + intArray( i );
product := product * intArray( i );
end for_i ;
end sumAndProduct ;
% test the sumAndProduct procedure %
begin
integer array v ( 1 :: 10 );
integer sum, product;
for i := 1 until 10 do v( i ) := i;
sumAndProduct( v, 1, 10, sum, product );
write( sum, product );
end
end.
You may also check:How to resolve the algorithm Rendezvous step by step in the Go programming language
You may also check:How to resolve the algorithm Gapful numbers step by step in the BASIC programming language
You may also check:How to resolve the algorithm Power set step by step in the AutoHotkey programming language
You may also check:How to resolve the algorithm Animate a pendulum step by step in the Euler Math Toolbox programming language
You may also check:How to resolve the algorithm Longest common subsequence step by step in the SequenceL programming language