求1!+3!+5!+…n!+++n的值从键盘输入
时间: 2023-11-24 09:51:25 浏览: 61
1_求1!+2!+...n!的值.c
以下是C语言实现求1!+3!+5!+…n!+++n的值从键盘输入的代码:
```c
#include <stdio.h>
int fun(int n);
int main() {
int n;
printf("请输入n的值:");
scanf("%d", &n);
int sum = 0;
for (int i = 1; i <= n; i += 2) {
sum += fun(i);
}
printf("1!+3!+5!+...+%d!的和为:%d\n", n, sum + n);
return 0;
}
int fun(int n) {
int res = 1;
for (int i = 1; i <= n; i++) {
res *= i;
}
return res;
}
```
阅读全文