输入在一行中给出小于1的阈值。
在一行中输出满足阈值条件的近似圆周率,输出到小数点后6位。
0.01
3.132157
ACCODE
#include
#include
using namespace std;
int main() {
double threshold;
cin >> threshold; // 输入阈值
double numerator = 1.0;
double denominator = 3.0;
double term = 1.0;
double sum = 1.0;
int limit1 = numerator;
int limit2 = denominator;
while(term >= threshold){
term = numerator/denominator;
sum += term;
limit1++;
limit2+=2;
numerator *= limit1;
denominator *= limit2;
}
cout << fixed << setprecision(6) << 2 * sum << endl;
return 0;
}