c语言1!+2!+3!+4!+……+n! n=20 (n为奇数)
时间: 2023-11-26 15:04:34 浏览: 94
C语言编写1!+2!+3!+.....+n!.doc
以下是C语言计算1!+2!+3!+4!+……+n!的代码,其中n=20且为奇数:
```c
#include <stdio.h>
int main()
{
int n = 20;
int sum = 0;
int factorial = 1;
for (int i = 1; i <= n; i++)
{
factorial *= i;
if (i % 2 == 1)
{
sum += factorial;
}
}
printf("%d\n", sum);
return 0;
}
```
阅读全文