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.




Program SumSeries;
type
  tOutput = double;//extended;
  tmyFunc = function(number: LongInt): tOutput;
 
function f(number: LongInt): tOutput;
begin
  f := 1/sqr(tOutput(number));
end;
 
function Sum(from,upto: LongInt;func:tmyFunc):tOutput;
var
  res: tOutput;
begin
  res := 0.0;
//  for from:= from to upto do res := res + f(from);
  for upTo := upto downto from do res := res + f(upTo);
  Sum := res;
end;
 
BEGIN
  writeln('The sum of 1/x^2 from 1 to 1000 is: ', Sum(1,1000,@f));
  writeln('Whereas pi^2/6 is:                  ', pi*pi/6:10:8);
end.