#include <iostream>
#include <iomanip>
using namespace std;
long int factorial(int n);
int main()
{
cout << "n e" << endl;
cout << "- -----------" << endl;
cout << "0 1" << endl << "1 2" << endl << "2 2.5" << endl;
for (int i = 3; i < 10; i++)
{
double e = 0;
cout << i << " ";
for (int j = 0; j <= i; j++)
{
e += 1.0 / factorial(j);
}
cout << fixed << setprecision(9) << e << endl;
}
return 0;
}
long int factorial(int n)
{
long int result = 1;
for (int i = 1; i <= n; i++)
result *= i;
return result;
}
继续加油。