Sum and product of an array: Difference between revisions
Content added Content deleted
(Sum and product of an array en BASIC256) |
Not a robot (talk | contribs) (Add CLU) |
||
Line 673: | Line 673: | ||
(defn product [vals] (reduce * vals))</lang> |
(defn product [vals] (reduce * vals))</lang> |
||
=={{header|CLU}}== |
|||
<lang clu>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</lang> |
|||
{{out}} |
|||
<pre>Sum = 55 |
|||
Product = 3628800</pre> |
|||
=={{header|COBOL}}== |
=={{header|COBOL}}== |