#include <stdio.h>
#include <math.h>
double calculate_series(int n) {
double sum = 0.0;
for (int i = 0; i < n; i++) {
sum
+= pow(-1, i
) / (2 * i
+ 1); }
return 4 * sum;
}
int main() {
int n1 = 3, n2 = 10;
printf("x(%d) = %.6f\n", n1
, calculate_series
(n1
)); printf("x(%d) = %.6f\n", n2
, calculate_series
(n2
)); return 0;
}
I2luY2x1ZGUgPHN0ZGlvLmg+CiNpbmNsdWRlIDxtYXRoLmg+Cgpkb3VibGUgY2FsY3VsYXRlX3NlcmllcyhpbnQgbikgewogICAgZG91YmxlIHN1bSA9IDAuMDsKICAgIGZvciAoaW50IGkgPSAwOyBpIDwgbjsgaSsrKSB7CiAgICAgICAgc3VtICs9IHBvdygtMSwgaSkgLyAoMiAqIGkgKyAxKTsKICAgIH0KICAgIHJldHVybiA0ICogc3VtOwp9CgppbnQgbWFpbigpIHsKICAgIGludCBuMSA9IDMsIG4yID0gMTA7CiAgICBwcmludGYoIngoJWQpID0gJS42ZlxuIiwgbjEsIGNhbGN1bGF0ZV9zZXJpZXMobjEpKTsKICAgIHByaW50ZigieCglZCkgPSAlLjZmXG4iLCBuMiwgY2FsY3VsYXRlX3NlcmllcyhuMikpOwogICAgcmV0dXJuIDA7Cn0K