用C编:求1!+2!+3!+4!....+20!

来源:百度知道 编辑:UC知道 时间:2024/08/20 13:04:41

修正版
#include<stdio.h>

void main()
{
int i,j,t=1,s=0;
for(i=1;i<=20;i++)
{
for(j=1;j<=i;j++)
t*=j;
s+=t;
t=1;//这里的t要再一次初始化!
}

printf("%d\n",s);

}

#include <stdio.h>
int fun(int n = 100)
{
int error = -1;
if(n < 0) return error;
if(n == 0 || n == 1) return 1;
int result = 1;
for( int i = n; i >= 2; i++)
result = (1 + i * result) * (--i);
return result;
}
void main()
{
int result = 0;
for(int i = 1; i < 21; i++)
result += fun(i);
printf("%d",result);
getch();
}
如果实在不够就换个大的long long,怎么都会够了吧

这个要用高精度
用数组算,很麻烦的……

#include<stdio.h>
int temp=1;
int nj=0;
for(int nIndex=1;nIndex<21;nIndex++)
{
for(int nIndex2=1;nIndex<=nIndex2;nIndex2++)
{