编剧王明娟的照片:这道"求1!+2!+3!+...8!"怎么做?哪位可以帮帮忙?谢谢!

来源:百度文库 编辑:高考问答 时间:2024/05/10 08:06:51

//用VC++6.0 递归
#include<iostream>
using namespace std;

int x(int a)
{
if(a==1)
return 1;
else
return a*(a-1);
}

void main()
{
int a,b(0);
for(a=1;a<=8;a++)
b+=x(a);
cout<<"1!+2!+3!+...8!="<<b<<endl;
}

#include "stdio.h"
main()
{int i,j;
long int k,s;
s=0;
for(i=1;i<=8;i++)
{k=1;
for(j=1;j<=i;j++)
k=k*j;
s=s+k;
}
printf("%ld\n",s);
getch();
}
输出结果为:46233

#include <stdio.h>
main()
{
int a,b,c=1,i,max=0;
for (i=1;i<=8;i++)
{
for (a=1;a<=i;a++)
{
c=c*a;
}
max=max+c;
}
printf("Number is %d",max);
getch();
}

1!+2!+……+8!
=1+1*2+1*2*3+1*2*3*4*5*6*7*8=46233

{pascal 语言}
program cao;
var
a,b:longint;
s,t:real;
begin
s:=0;
for a:=1 to 8 do
begin
t:=1;
for b:=1 to a do
t:=t*b;
s:=s+t;
end;
write(s);
end.
{结果是46233}

等于36啊