#include<stdio.h>
int main() {
int n = 0;
printf("请输入一个正整数:");
scanf_s("%d", &n);
int all = 0;
int sun = 0;
for (int i = 1; i < n+1; i++) {
for (int j = 1,sum=1; j < i+1; j++) {
sum = j * sum;
sun = sum;
}
all = all + sun;
}
printf("1-%d的阶乘之和为:%d", n, all);
return 0;
}
#include<stdio.h>标签:两种,方式,int,sun,sum,++,printf,阶乘 From: https://blog.51cto.com/u_13606048/6086623
int main() {
int n = 0;
printf("请输入一个正整数:");
scanf_s("%d", &n);
int all = 0;
int sum = 1;
for (int i = 1; i < n+1; i++) {
sum = sum * i;
all = all + sum;
}
printf("1-%d的阶乘之和为:%d", n, all);
return 0;
}