#include <iostream> using namespace std; #include <bits/stdc++.h> int main() { int n = 0; //定义变量 int denominator = 0; //分母 double sum = 0; cin >> n; for (int i = 1; i <= n; i++) { //计算分母,当i为奇数 if (i % 2 == 1) { denominator += 2 * i - 1; } //i位偶数 else { denominator -= 2 * i - 1; } //计算总和 sum += 1.0 / denominator; } cout << fixed << setprecision(3) << sum; system("pause"); return 0; }