首先fac函数没有定义返回类型;
还有就是计算阶乘和计算的只是n的阶乘;
#include
int fac(int n) //返回类型为int型
{
int sum = 0;
int sum1 = 1;
for(int j = 1; j <= n; j++) //从1开始计算阶乘,计算到n
{
for(int i = 1; i <= j; i++)
{
sum1 *= i;
}
sum += sum1;
}
return sum;
}
int main(void)
{
int n1;
int result;
printf("随意输入整数n,求1!+2!+...+n!的和:\n");
scanf("%d",&n1);
result = fac(n1);
printf("%d",result);
return 0;
}