提交时间:2023-11-02 18:43:12
运行 ID: 29718
#include <iostream> #include <iomanip> using namespace std; int main() { int n; float sum; cin >> n; sum = 0; for(int i=1; i<=n; i++) { if(i % 2 == 1) sum += 1.0 / i; else sum -= 1.0 / i; } cout << fixed << setprecision(4) << sum << endl; return 0; }