Task

Compute the sum and product of an array of integers.




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