C语言求1到n阶乘之和
时间: 2023-05-21 11:04:05 浏览: 172
1到n的阶乘求和
您好,以下是C语言代码,用于求1到n阶乘之和:
```
#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到%d的阶乘之和为:%d\n", n, sum);
return 0;
}
```
希望能够帮到您!
阅读全文