求1!+3!+5!+...+n!的和
时间: 2023-11-24 17:51:55 浏览: 96
java基础编程:求1+2!+3!+...的前n项的和
以下是C语言程序设计中求1!+3!+5!+...+n!的和的代码:
```c
#include <stdio.h>
int main()
{
int n, i, j, sum = 0, fac = 1;
printf("请输入n的值:");
scanf("%d", &n);
for (i = 1; i <= n; i += 2) {
fac = 1;
for (j = 1; j <= i; j++) {
fac *= j;
}
sum += fac;
}
printf("1!+3!+5!+...+n!的和为:%d\n", sum);
return 0;
}
```
运行结果如下:
```
请输入n的值:5
1!+3!+5!+...+n!的和为:33
```
阅读全文