Compute the   nth   term of a series,   i.e. the sum of the   n   first terms of the corresponding sequence.

Informally this value, or its limit when   n   tends to infinity, is also called the sum of the series, thus the title of this task.

For this task, use:

 




S

n


=

∑

k
=
1


n




1

k

2






{\displaystyle S_{n}=\sum _{k=1}^{n}{\frac {1}{k^{2}}}}




 and compute   




S

1000




{\displaystyle S_{1000}}




This approximates the   zeta function   for   S=2,   whose exact value

 



ζ
(
2
)
=



π

2


6




{\displaystyle \zeta (2)={\pi ^{2} \over 6}}


is the solution of the Basel problem.




begin % compute the sum of 1/k^2 for k = 1..1000 %
    integer k;
    % computes the sum of a series from lo to hi using Jensen's Device %
    real procedure sum  ( integer %name% k; integer value lo, hi; real procedure term );
    begin
        real temp;
        temp := 0;
        k := lo;
        while k <= hi do begin
            temp := temp + term;
            k := k + 1
        end while_k_le_temp;
        temp
    end;
    write( r_format := "A", r_w := 8, r_d := 5, sum( k, 1, 1000, 1 / ( k * k ) ) )
end.