POJ 1517
题意
求e
思路
注意前三个输出就ok了
#include <iostream>
#include <cmath>
#include <algorithm>
using namespace std;
int main(){
double sum = 2.5;
cout<<"n e"<<endl;
cout<<"- -----------"<<endl;
for(int i = 0;i<=9;i++){
if(i==0) cout<<"0 1"<<endl;
else if(i==1) cout<<"1 2"<<endl;
else if(i==2) cout<<"2 2.5"<<endl;
else{
double temp=1;
for(int j=1;j<=i;j++){
temp*=j;
}
sum = sum + 1/temp;
cout<<i<<" "<<fixed<<sum<<endl;
}
}
return 0;
}