#include <stdio.h>
double calculate_series(int n) {
double sum = 0.0; // 級数の和
for (int k = 1; k <= n; k++) {
sum += 1.0 / (k * (k + 1)); // 各項を計算して加算
}
return sum;
}
int main() {
int n1 = 3, n2 = 10; // 計算対象の n の値
double result1, result2;
// n=3 のときの計算
result1 = calculate_series(n1);
printf("n = %d のとき、x(n) = %.6f\n", n1
, result1
);
// n=10 のときの計算
result2 = calculate_series(n2);
printf("n = %d のとき、x(n) = %.6f\n", n2
, result2
);
return 0;
}
I2luY2x1ZGUgPHN0ZGlvLmg+Cgpkb3VibGUgY2FsY3VsYXRlX3NlcmllcyhpbnQgbikgewogICAgZG91YmxlIHN1bSA9IDAuMDsgLy8g57Sa5pWw44Gu5ZKMCgogICAgZm9yIChpbnQgayA9IDE7IGsgPD0gbjsgaysrKSB7CiAgICAgICAgc3VtICs9IDEuMCAvIChrICogKGsgKyAxKSk7IC8vIOWQhOmgheOCkuioiOeul+OBl+OBpuWKoOeulwogICAgfQoKICAgIHJldHVybiBzdW07Cn0KCmludCBtYWluKCkgewogICAgaW50IG4xID0gMywgbjIgPSAxMDsgLy8g6KiI566X5a++6LGh44GuIG4g44Gu5YCkCiAgICBkb3VibGUgcmVzdWx0MSwgcmVzdWx0MjsKCiAgICAvLyBuPTMg44Gu44Go44GN44Gu6KiI566XCiAgICByZXN1bHQxID0gY2FsY3VsYXRlX3NlcmllcyhuMSk7CiAgICBwcmludGYoIm4gPSAlZCDjga7jgajjgY3jgIF4KG4pID0gJS42ZlxuIiwgbjEsIHJlc3VsdDEpOwoKICAgIC8vIG49MTAg44Gu44Go44GN44Gu6KiI566XCiAgICByZXN1bHQyID0gY2FsY3VsYXRlX3NlcmllcyhuMik7CiAgICBwcmludGYoIm4gPSAlZCDjga7jgajjgY3jgIF4KG4pID0gJS42ZlxuIiwgbjIsIHJlc3VsdDIpOwoKICAgIHJldHVybiAwOwp9Cg==