#include <stdio.h>
double calculate_x(int n) {
double sum = 0.0;
for (int i = 1; i <= n; i++) {
sum += 1.0 / (i * (i + 1));
}
return sum;
}
int main() {
int n1 = 3;
int n2 = 10;
printf("x(%d) = %.6f\n", n1
, calculate_x
(n1
)); printf("x(%d) = %.6f\n", n2
, calculate_x
(n2
));
return 0;
}
I2luY2x1ZGUgPHN0ZGlvLmg+Cgpkb3VibGUgY2FsY3VsYXRlX3goaW50IG4pIHsKICAgIGRvdWJsZSBzdW0gPSAwLjA7CiAgICBmb3IgKGludCBpID0gMTsgaSA8PSBuOyBpKyspIHsKICAgICAgICBzdW0gKz0gMS4wIC8gKGkgKiAoaSArIDEpKTsKICAgIH0KICAgIHJldHVybiBzdW07Cn0KCmludCBtYWluKCkgewogICAgaW50IG4xID0gMzsKICAgIGludCBuMiA9IDEwOwoKICAgIHByaW50ZigieCglZCkgPSAlLjZmXG4iLCBuMSwgY2FsY3VsYXRlX3gobjEpKTsKICAgIHByaW50ZigieCglZCkgPSAlLjZmXG4iLCBuMiwgY2FsY3VsYXRlX3gobjIpKTsKCiAgICByZXR1cm4gMDsKfQo=