求e=1+1/1!+2*2!+…+n/n!,输入n=10用c语言实现
时间: 2023-10-02 16:12:30 浏览: 51
c语言求1+2+...+n的解决方法
以下是实现代码:
```c
#include <stdio.h>
int main() {
int n = 10;
double e = 1.0, term = 1.0;
for (int i = 1; i <= n; i++) {
term *= i;
e += 1.0 / term;
}
printf("e = %lf\n", e);
return 0;
}
```
运行结果:
```
e = 2.718282
```
阅读全文