阶乘和

来源:互联网 发布:东北大学网络教育好吗 编辑:程序博客网 时间:2024/04/30 13:04

【题目描述】
    计算表达式的值:s=1!+2!+3!+…+n!,其中n由键盘输入。

【解题思路】
递归函数vari,n,sum;longint;function jie(x:longint):longint;vari,ans:integer;beginif x=1 thenjie:=1elseans:=jie(x-1)*x;jie:=ans;end;beginreadln(n);sum:=0;for i:=1 to n dosum:=sum+jie(i);writeln(sum);end;

【完整代码】

var  t,s,i,n:longint;begin  readln(n);  s:=0 t:=1;  for i:=1 to n do  begin  t:=t*i;  s:=s+t;  end;  writeln(s);  end