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