使用c语言求s=1+1/1!+1/2!+1/3!+...+1/N!
时间: 2023-10-09 09:10:57 浏览: 799
c++求1+1/2+1/3+...+1/n
5星 · 资源好评率100%
#include <stdio.h>
int main() {
int n, i;
double s = 1, factorial = 1;
printf("请输入n的值:");
scanf("%d", &n);
for (i = 1; i <= n; i++) {
factorial *= i; //计算i的阶乘
s += 1 / factorial; //累加1/i!的值
}
printf("s=%f\n", s);
return 0;
}
阅读全文