#include
#include
using namespace std;
int main(){
int n,i;
cin>>n;
double t,result=2.0/1+3.0/2;
int a1,a2,a3;
a1=1;
a2=2;
a3=3;
for(i=1;i<=n;i++){
if(i==1)
result=2.0/1;
else if(i==2)
result=2.0/1+3.0/2;
else{
a1=a2;
a2=a3;
a3=a1+a2;
t=(double)a3/a2;
result+=t;
}
}
cout<<fixed<<setprecision(4)<<result<<endl;
return 0;
}
為什麼輸入的數大於50得出的結果就不對了
result=2.0/1.0+3.0/2.0;
t=(double)a3/(double)a2;
都要修改