提交时间:2024-02-22 19:43:22
运行 ID: 41626
#include<bits/stdc++.h> using namespace std; int main(){ int n; cin >> n; double sum = 1; double i = 1; int a = 0; while(i<=n){ if(a == 0){ sum -= 1/i; } else if(a == 1){ sum += 1/i; } a = !a; i++; } cout << fixed << setprecision (4) << sum; return 0; }