% Die naeherungsweise Berechnung von PI

% Teil I
err = 1e-12;
n = 1;
s = 1/(((2*n-1)*(2*n+1))^2);

while (abs(pi-sqrt(16*s+8)) >= err)
    n = n + 1;
    s = s + 1/(((2*n-1)*(2*n+1))^2);
end
n

% Teil II
max_it = 100;
n = 1;
s = 1/(((2*n-1)*(2*n+1))^2);

while (n < max_it)
    n = n + 1;
    s = s + 1/(((2*n-1)*(2*n+1))^2);
end
err = abs(pi-sqrt(16*s+8))