#include <stdio.h>
double calculate_sum(int n) {
double sum = 0.0;
for (int k = 1; k <= n; k++) {
sum += 1.0 / (k * (k + 1)); // セミコロンを付けて修正
}
return sum;
}
int main(void) {
int n1 = 3;
int n2 = 10;
double result_n1 = calculate_sum(n1);
double result_n2 = calculate_sum(n2);
printf("x(%d) = %f\n", n1
, result_n1
); printf("x(%d) = %f\n", n2
, result_n2
);
return 0;
}
I2luY2x1ZGUgPHN0ZGlvLmg+CmRvdWJsZSBjYWxjdWxhdGVfc3VtKGludCBuKSB7CiAgICBkb3VibGUgc3VtID0gMC4wOwogICAgZm9yIChpbnQgayA9IDE7IGsgPD0gbjsgaysrKSB7CiAgICAgICAgc3VtICs9IDEuMCAvIChrICogKGsgKyAxKSk7IC8vIOOCu+ODn+OCs+ODreODs+OCkuS7mOOBkeOBpuS/ruatowogICAgfQogICAgcmV0dXJuIHN1bTsKfQoKaW50IG1haW4odm9pZCkgewogICAgaW50IG4xID0gMzsKICAgIGludCBuMiA9IDEwOwogICAgZG91YmxlIHJlc3VsdF9uMSA9IGNhbGN1bGF0ZV9zdW0objEpOwogICAgZG91YmxlIHJlc3VsdF9uMiA9IGNhbGN1bGF0ZV9zdW0objIpOwoKICAgIHByaW50ZigieCglZCkgPSAlZlxuIiwgbjEsIHJlc3VsdF9uMSk7CiAgICBwcmludGYoIngoJWQpID0gJWZcbiIsIG4yLCByZXN1bHRfbjIpOwogIApyZXR1cm4gMDsKfQ==