用c使用double计算s=3!+6!+9!+…+18!
时间: 2023-11-22 13:23:34 浏览: 48
#include <stdio.h>
double factorial(int n) {
double result = 1.0;
for (int i = 1; i <= n; i++) {
result *= i;
}
return result;
}
int main() {
double s = 0.0;
for (int i = 1; i <= 6; i++) {
int n = 3 * i;
double f = factorial(n);
s += f;
printf("%d! = %g\n", n, f);
}
printf("s = %g\n", s);
return 0;
}
阅读全文