求1+1/1!+1/2!+1/3!+1/4!+...前 100项之和C语言代码
时间: 2023-11-15 19:04:57 浏览: 97
以下是求解1+1/1!+1/2!+1/3!+1/4!+...前100项之和的C语言代码:
引用:
#include <stdio.h>
int main(){
int i = 1;
double sum = 0.0;
for (i = 1; i <= 100; ++i){
double factorial = 1.0;
int j;
for (j = 1; j <= i; ++j){
factorial *= j;
}
sum += 1.0/factorial;
}
printf ("%f\n", sum);
return 0;
}
阅读全文