You can not select more than 25 topics Topics must start with a letter or number, can include dashes ('-') and can be up to 35 characters long.

21 lines
500 B

#include <bits/stdc++.h>
using namespace std;
int main() {
//读入输出优化的强迫症
ios::sync_with_stdio(false);
double sum = 0;
for (int i = 0;; i++) {
double term = 1.0 / (i * 2 + 1);
if (i % 2 == 0)sum += term;
else sum -= term;
if (term < 1e-6) break; //注意科学记数法
}
printf("%.6f\n", sum); //保留六位小数
//本程序耗时
printf("Time used = %.2f\n", (double) clock() / CLOCKS_PER_SEC);
return 0;
}