前面几个数比较简单,但到后面数越来越大,所以我建议用定义类型用int64,这样就不会超界了。不过仅是针对这道题。如果n的取值范围再大一点,你就得用高精度计算了。 下面是程序: ar n:1..15;s,a:int64;i,j:integer; begin readln(n); for i:=1 to n do begin a:=1; for j:=1 to i do a:=a*j; s:=s+a; end; write(s); end. 希望对你有用!
var i,n,s2:longint; function jc(x:longint):longint; var i:longint; begin jc:=1; for i:=1 to x do jc:=jc*i; end; begin s2:=0; readln(n); for i:=1 to n do s2:=jc(i)+s2; writeln(s2); end.