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.




INCLUDE "D2:REAL.ACT" ;from the Action! Tool Kit
 
PROC Calc(CARD n REAL POINTER res)
  CARD i,st
  BYTE perc
  REAL one,a,b
 
  IntToReal(0,res)
  IF n=0 THEN RETURN FI
 
  IntToReal(1,one)
  st=n/100
  FOR i=1 TO n
  DO
    IF i MOD st=0 THEN
      PrintB(perc) Put('%) PutE() Put(28)
      perc==+1
    FI
 
    IntToReal(i,a)
    RealMult(a,a,b)
    RealDiv(one,b,a)
    RealAdd(res,a,b)
    RealAssign(b,res)
  OD
RETURN
 
PROC Main()
  REAL POINTER res
  CARD n=[1000]
 
  Put(125) PutE() ;clear screen
  Calc(n,res)
  PrintF("s(%U)=",n)
  PrintRE(res)
RETURN