c语言编程题,计算1+2!+3!+4!+······+10!的值怎么编程呀??具体的步骤。。。。。

2024-11-23 19:17:47
推荐回答(4个)
回答1:

您看满意否,满意请采纳
#include

void main ()
{
int n = 1, i;
int sum = 0;
for (i = 1; i <= 10; ++i)
{
n *= i;
sum += n;
}
printf("结果为:%d", sum);
}

回答2:

#include
void main ()
{
int i,n,j,sum=0;
int m;
scanf("%d",&n);
for(i=1;i<=n;++i)
{
m=1;
for(j=1;j<=i;++j)
m*=j;
sum=sum+m;
}
printf("1!+2!+...n!=%d\n",sum);
}

回答3:

#include
main()
{
int i,j;
int s=0;
for(i=1;i<=10;i++)
{
int s1=1;
for(j=1;j<=i;j++)
s1=s1*j;
s=s+s1;
}
printf("%d",s);
}

回答4:

#include

int main()
{
int sum = 0;
int step = 1;
int i;
for(i=1;i<=10;i++)
{
step *= i;
sum += step;
}
printf("Answer = %d\n",sum);
}