编写程序计算s=1+1⼀2!+1⼀3!+1⼀4!...+1⼀n!。n由终端输入,将计算n!定义成函数。(要求定义函数sum求和,

2024-11-01 16:02:43
推荐回答(1个)
回答1:

var
s:real;

n:longint;
function jc(x:longint):longint;
var
i:longint;

begin
jc:=1;

for i:=2 to x do

jc:=jc*i;

end;
function sum:real;
var
i:longint;

begin
sum:=0;

for i:=1 to n do

sum:=sum+1/js(i);

end;
begin
readln(n);

s:=sum;
writeln(s);
end.