% Script series
% 1 + 1/2^2 + 1/3^2 + ... 1/n^2 approaches pi^2/6.
% Compute the aprroximate values and errors for n terms.

disp('Compute the series 1 + 1/2^2 + 1/3^2 + ... 1/n^2')
n= input('How many terms? ');

fprintf('\n n approximation error \n')
value= pi^2/6;
approx= 0;
for k= 1:n
approx= approx + 1/k^2;
err= value - approx;
% display result for first 4 and last 4 approxmiations
if k<5 || k>n-4
fprintf('%4d %13.6f %+8e \n', k, approx, err)
end
end