计算 s=1-2!+3!-4!+......-10!的值并输出.

1
2024-12-16 18:10:33
推荐回答(3个)
回答1:

用什么语言?

使用ASP VB

for i=1 to 10
for j=1 to i
sum1=sum1*j
next
sum=sum+(-1)^(i-1)
next
response.write "值为:"&sum

若是其它语言也是一样的思路.

就是 -1的(i-1)次方乘以i的阶乘之和

回答2:

#include
int multiple(int);
main()
{
int i,n,flag;
int sum;
for(sum=0,flag=-1,i=1;i<=10;i++){
sum+=(flag*(-1))*multiple(i);
flag*=-1;
}
printf("the answer is %d\n",sum);
}

int multiple(int n)
{
int temp,i;
int answer;
for(answer=1,i=1;i<=n;i++)
answer*=i;
return answer;
}
临时写的,能算出来

回答3:

#include
unsigned int jiecheng(unsigned int data)
{
unsigned int value=1;
int i=1;
value
for(i=1;i<=data;i++)
{
value=i*value;
}
return(value);
}
void main()
{
int i=1;
unsigned int temp=0,value=0;
while(i<=10)
{
temp=jiecheng(i);
value=value+temp;
}
printf("the result is %d\n",value);
}