#include <stdio.h>
// 級数を計算する関数
double calculate_series(int n) {
double sum = 0.0;
for (int i = 1; i <= n; i++) {
sum += 1.0 / (i * (i + 1));
}
return sum;
}
int main(void) {
int n; // 入力する項数
double result;
// n の入力を受け取る
// 級数の計算
result = calculate_series(n);
// 結果の出力
printf("n = %d のときの x(n) の値: %.6f\n", n
, result
);
return 0;
}
I2luY2x1ZGUgPHN0ZGlvLmg+CgovLyDntJrmlbDjgpLoqIjnrpfjgZnjgovplqLmlbAKZG91YmxlIGNhbGN1bGF0ZV9zZXJpZXMoaW50IG4pIHsKICAgIGRvdWJsZSBzdW0gPSAwLjA7CiAgICBmb3IgKGludCBpID0gMTsgaSA8PSBuOyBpKyspIHsKICAgICAgICBzdW0gKz0gMS4wIC8gKGkgKiAoaSArIDEpKTsKICAgIH0KICAgIHJldHVybiBzdW07Cn0KCmludCBtYWluKHZvaWQpIHsKICAgIGludCBuOyAvLyDlhaXlipvjgZnjgovpoIXmlbAKICAgIGRvdWJsZSByZXN1bHQ7CgogICAgLy8gbiDjga7lhaXlipvjgpLlj5fjgZHlj5bjgosKICAgIHByaW50ZigibiDjgpLlhaXlipvjgZfjgabjgY/jgaDjgZXjgYQ6ICIpOwogICAgc2NhbmYoIiVkIiwgJm4pOwoKICAgIC8vIOe0muaVsOOBruioiOeulwogICAgcmVzdWx0ID0gY2FsY3VsYXRlX3NlcmllcyhuKTsKCiAgICAvLyDntZDmnpzjga7lh7rlipsKICAgIHByaW50ZigibiA9ICVkIOOBruOBqOOBjeOBriB4KG4pIOOBruWApDogJS42ZlxuIiwgbiwgcmVzdWx0KTsKCiAgICByZXR1cm4gMDsKfQ==