设计程序计算1!+2!+…+n!用C语言
时间: 2023-11-24 09:51:54 浏览: 57
求解不等式C语言小程序代码.txt
以下是用C语言设计程序计算1!+2!+…+n!的代码:
```c
#include <stdio.h>
int main()
{
int n, i, j, factorial, sum = 0;
printf("请输入一个正整数n:");
scanf("%d", &n);
for (i = 1; i <= n; i++)
{
factorial = 1;
for (j = 1; j <= i; j++)
{
factorial *= j;
}
sum += factorial;
}
printf("1!+2!+...+%d!=%d", n, sum);
return 0;
}
```
阅读全文