首页 > 代码库 > hdu 1012 u Calculate e

hdu 1012 u Calculate e

#include<iostream>

#include<iomanip>

using namespace std;

int main(){
cout << "n" << ‘ ‘ << "e" << endl;
cout << "-" << ‘ ‘ << "-----------" << endl;
cout << 0 << ‘ ‘ << 1 << endl;
cout << 1 << ‘ ‘ << 2 << endl;
cout << 2 << ‘ ‘ << 2.5 << endl;
long double sum = 2.5;
long double a = 1;
for (int i = 3; i <= 9; i++){
long double temp = 1;
for (int j = 1; j <= i; j++)
temp *= j;
sum += a/ temp;
cout << i << ‘ ‘ << setiosflags(ios::fixed) << setprecision(9) << sum << endl;
}
return 0;
}