program p8_1_a uses crt function fac integer longint var integer longi

 1
 2
 3
 4
 5
 6
 7
 8
 9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
program p8_1_a;
uses crt;
function fac(n : integer) : longint;
var i : integer; f : longint;
begin
f := 1;
for i := 2 to n do
f := f * i;
fac := f;
end;
function fs(n : integer) : real;
var i : integer; s: real;
begin
i := 2; s := 1;
repeat
s := s + 1/fac(i);
i := i + 1;
until i > n;
fs := s;
end;
var n : integer; s : real;
begin
clrscr;
s := fs(10);
writeln('n = 10, s = ', s:2:20);
s := fs(20);
writeln('n = 20, s = ', s:2:20);
s := fs(30);
writeln('n = 30, s = ', s:2:20);
readln;
end.