-- Inputs an integer n and sums the ints and their squares from 1 to n
-- Another example showing In Out mode parameters
with ada.integer_text_io; use ada.integer_text_io;
with ada.Numerics.Elementary_Functions; use ada.Numerics.Elementary_Functions;
procedure modes3 is
procedure calcs(n: Natural; s, ssq: in out Natural) is
begin
s := s + n;
ssq := ssq + n**2;
end calcs;
-- Restrict the range. Cube root would be better, but no time to find it!
n: Natural range 0 .. Integer(sqrt(float(Natural'last)));
sumUpToN, sumSqUpToN: Natural := 0;
begin
get(n);
for k in 1 .. n loop
calcs(k, sumUpToN, sumSqUpToN);
end loop;
put(sumUpToN);
put(sumSqUpToN);
end modes3;
-- Input: 5
-- Output: 15 55