编写c语言程序计算S=1+1/1!+1/2!+1/3!......+1/n!
时间: 2023-12-07 15:38:40 浏览: 300
(完整版)c语言程序设计编程题库.doc
以下是一个C语言程序,用于计算S=1+1/1!+1/2!+1/3!......+1/n!:
```c
#include <stdio.h>
int main() {
int n, i, j;
double sum = 1, fac = 1;
printf("请输入n的值:");
scanf("%d", &n);
for (i = 1; i <= n; i++) {
fac *= i;
sum += 1.0 / fac;
}
printf("S的值为:%lf", sum);
return 0;
}
```
阅读全文