'commit'
This commit is contained in:
21
RuMenJingDian/Others/L_2_3.cpp
Normal file
21
RuMenJingDian/Others/L_2_3.cpp
Normal file
@@ -0,0 +1,21 @@
|
||||
#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;
|
||||
}
|
||||
Reference in New Issue
Block a user