编写一个程序:求1!+2!+3!+4!+···+20!

2024-12-28 05:39:11
推荐回答(2个)
回答1:

#include
void main()
{int sum=0,a=1,i,b=1;
for (;a<=20;a++)
{for (i=1;i<=a;i++)
b*=i;
sum+=b;}
printf("sum=%d",sum);}

回答2:

#include
#pragma hdrstop
#include
//---------------------------------------------------------------------------
using namespace std;
#pragma argsused
int main(int argc, char* argv[])
{
int i,n=20,sum=0,t=1;
for(i=1;i<=n;i++)
{
t*=i;
sum+=t;
}
cout<<"sum ="< system("pause");
return 0;
}