C语言计算e=1+1/1!+1/2!+1/3!+……+1/n!
时间: 2023-09-16 08:13:02 浏览: 476
6+1彩票中奖数据结构课程设计
5星 · 资源好评率100%
```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
```
阅读全文