编写程序计算1!+2!+·······+n!。n的值由键盘输入(n的值在10以内)(用函数)
#include<stdio.h>
int main()
{
int n,i;
long fac;
scanf("%d",&n);
printf("%d",py(n));
return 0;
}
int py(int k)
{
int sum,i;
long fac;
fac=1,sum=0;
for(i=1;i<=k;i++)
{
fac=i*fac;
sum=fac+sum;
}
return sum;
}