#include
long jiecheng(long a);
long jiechenghe(long n);
int main(void)
{
long n,y;
printf("input n:");
scanf("%ld",&n);
y=jiechenghe(n);
printf("sum is %ld\n",y);
}
long jiecheng(long a)
{
long ji=1;
for(long i=1;i<=a;i++)
ji=ji*i;
return ji;
}
long jiechenghe(long n)
{
long sum=0;
for(int i=1;i<=n;i++)
sum+=jiecheng(i);
return sum;
}
范围再大,也不能更大了。
参考 http://zhidao.baidu.com/question/498764348.html
#include
#include
#include
void main()
{
long int sum1=1;
long int sum=0;
int i=0;
int nu=0;
scanf("%d",&i);
while(i!=0)
{
nu=i;
while(nu!=0)
{
sum1*=nu;
nu--;
}
sum+=sum1;
sum1=1;
i--;
}
printf("%ld\n",sum);
}
sum 精度不够的话你定义成double类型就可以了