不是VIP会员,不能显示答案

题目解答

题目:
用高精度计算出S=1!+2!+3!+……n!(n≤),其中“ !”表示阶乘。输入正整数N,输出计算结果S
program t5;
const maxlen=100;
var i,j,n:integer;
    sum,fac:array[1..maxlen+1] of integer;
begin
  write('input n:');
  readln(n);
  for i:=1 to maxlen do sum[i]:=0;
  for i:=1 to maxlen do fac[i]:=0;
  fac[1]:=1;
  for i:=1 to n do
  begin
    for j:=1 to maxlen do    fac[j]:=fac[j]*i   ;
    for j:=1 to maxlen do
begin
fac[j+1]:=fac[j+1]+fac[j] div 10;
     fac[j]:= fac[j] mod 10  ;
      end;
    for j:=1 to maxlen do sum[j]:=sum[j]+fac[j] ;
    for j:=1 to maxlen do
      begin
        sum[j+1]:= sum[j+1]:=sum[j+1]+sum[j] div 10  ;
        sum[j]:=sum[j] mod 10
      end;
    end;
    i:=maxlen;
    while sum[i]=0 do i:=i-1;
    write('s=');
    for j:=   i downto 1  do write(sum[j]);
    writeln
  end.
考点:
分析:
解答:
评论:
老师: