注意
- 輸入值是浮點(diǎn)數(shù)
- 判斷最小一項(xiàng)是否小于等于輸入值
- 直接計(jì)算會(huì)超出長(zhǎng)整形
- 保留6位小數(shù)
- 輸入時(shí)double類(lèi)型需要用lf來(lái)讀入
代碼
#include <iostream>
#include <cstdio>
using namespace std;
int main(){
double x;
scanf("%lf", &x);
double sum = 1;
int t = 1;
double last = 1;
while(last >= x){
last = last*t/(2*t+1);
sum += last;
t++;
}
printf("%.6f\n", sum*2);
return 0;
}