#include<stdio.h>
int fact(int x);
int main()
{
int n;
scanf("%d", &n);
if (n > 15) { //当n大于15后,sum的值是一样的
n = 15;
}
double sum = 1.0;
for (int i = 1; i <= n; i++) {
sum = sum + 1.0 / fact(i);
}
printf("%.8lf", sum);
}
int fact(int x) {
int a = 1;
for (int i = 1; i <= x; i++) {
a = a * i;
}
return a;
}
&&
#include<stdio.h>
#include<math.h>
int main()
{
double x;
scanf("%lf", &x);
double sum = 1.0;
double b = 1;
for (int i = 1;; i++) {
b = i * b;
double a= pow(x, i) / b * 1.0;
sum = sum + a;
if (a < 1e-5) {
break;
}
}
printf("%.4lf", sum);
}