#include 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; }