Task

Compute the sum and product of an array of integers.




MODULE Sumprod EXPORTS Main;
 
FROM IO IMPORT Put;
FROM Fmt IMPORT Int;
 
VAR a := ARRAY [1..5] OF INTEGER {1, 2, 3, 4, 5};
VAR sum: INTEGER := 0;
VAR prod: INTEGER := 1;
 
BEGIN
  FOR i := FIRST(a) TO LAST(a) DO
    INC(sum, a[i]);
    prod := prod * a[i];
  END;
  Put("Sum of array: " & Int(sum) & "\n");
  Put("Product of array: " & Int(prod) & "\n");
END Sumprod.