How to resolve the algorithm Sum and product of an array step by step in the CLU 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 CLU 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 CLU programming language

Source code in the clu programming language

sum_and_product = proc (a: array[int]) returns (int,int) signals (overflow)
    sum: int := 0
    prod: int := 1
    for i: int in array[int]$elements(a) do
        sum := sum + i
        prod := prod * i
    end resignal overflow
    return(sum, prod)
end sum_and_product

start_up = proc ()
    arr: array[int] := array[int]$[1,2,3,4,5,6,7,8,9,10]
    sum, prod: int := sum_and_product(arr)
    
    po: stream := stream$primary_output()
    stream$putl(po, "Sum = " || int$unparse(sum))
    stream$putl(po, "Product = " || int$unparse(prod))
end start_up

  

You may also check:How to resolve the algorithm Determine sentence type step by step in the Racket programming language
You may also check:How to resolve the algorithm FASTA format step by step in the BASIC programming language
You may also check:How to resolve the algorithm Abbreviations, automatic step by step in the C++ programming language
You may also check:How to resolve the algorithm Letter frequency step by step in the Nanoquery programming language
You may also check:How to resolve the algorithm Gaussian elimination step by step in the Ada programming language