C语言计算e=1+1/1!+1/2!+1/3!+……+1/n!
时间: 2023-09-16 11:13:02 浏览: 463
C语言编写1!+2!+3!+.....+n!.doc
```c
#include <stdio.h>
int main() {
int n;
double e = 1.0, f = 1.0;
printf("请输入n:");
scanf("%d", &n);
for (int i = 1; i <= n; i++) {
f = f * i;
e += 1 / f;
}
printf("e = %lf\n", e);
return 0;
}
```
运行结果:
```
请输入n:10
e = 2.718282
```
阅读全文