代码如下,
#include
int func(int n)
{
int i;
int result=0, fac =1;
for(i = 1; i <= n; i ++)
{
fac*=i;
result += fac;
}
return result;
}
int main()
{
int n;
scanf("%d",&n);
printf("%d\n",func(n));
return 0;
}
如果需要支持大数 可以
#include
doublefunc(int n)
{
int i;
double result=0, fac =1;
for(i = 1; i <= n; i ++)
{
fac*=i;
result += fac;
}
return result;
}
int main()
{
int n;
scanf("%d",&n);
printf("%.0lf\n",func(n));
return 0;
}
#include
int fact(int n)
{
int ans = 1, i;
for (i = 1; i <= n; ++i){
ans *= i;
}
return ans;
}
int main()
{
int n, i, sum = 0;
scanf ("%d", &n);
for (i = 1; i <= n; ++i){
sum += fact(i);
}
printf ("%d\n", sum);
return 0;
}
void fun(int n)
{
int num = 1;
int sum = 0;
for (int i = 1;i
{
for(j = 1;j<=i;j++)
{
num* = j;
}
sum+ = num;
num = 1;
printf("%d\n",sum);
}
}