c语言编写程序求无理数e输出计算公e=1+1/1!+1/!2+1/3+...+1/n!1当1/n!<0.000001时e=2.718282
时间: 2023-12-04 15:04:11 浏览: 106
C语言程序设计-功能:编写程序求无理数e的值并输出;计算公式为:e=1+11!+12!+13!+......+1n!当1n!
5星 · 资源好评率100%
以下是C语言编写程序求无理数e输出计算公式e=1+1/1!+1/!2+1/3+...+1/n!1当1/n!<0.000001时e=2.718282的例子:
```c
#include <stdio.h>
int main() {
int n = 1;
double e = 1, factorial = 1;
while (1) {
factorial *= n;
double term = 1.0 / factorial;
if (term < 0.000001) {
break;
}
e += term;
n++;
}
printf("e = %lf\n", e);
return 0;
}
```
运行结果为:
```
e = 2.718282
```
阅读全文