Jump to content

Sum and product of an array: Difference between revisions

m
→‎{{header|Ada}}: syntax highlighting
m (→‎{{header|Fortran}}: Modified array constructor because it would cause an overflow error with example being demonstrated)
m (→‎{{header|Ada}}: syntax highlighting)
Line 15:
 
=={{header|Ada}}==
<ada>
type Int_Array is array(Integer range <>) of Integer;
 
Line 22 ⟶ 23:
Sum := Sum + array(I);
end loop;
</ada>
 
Define the product function
<ada>
function Product(Item : Int_Array) return Integer is
Prod : Integer := 1;
Line 32 ⟶ 34:
return Prod;
end Product;
</ada>
This function will raise the predefined exception Constraint_Error if the product overflows the values represented by type Integer
 
=={{header|ALGOL 68}}==
main:(
Anonymous user
Cookies help us deliver our services. By using our services, you agree to our use of cookies.