a)
program Tong_5a;
uses crt;
var y: real;
n: byte;
Begin
clrscr
y:=0;
for n :=1 to 50 do
y:=y + n / ( n +1 ) ;
writeln('Tong y la: y:0:18);
readln;
End.
Nếu biến y khai báo theo kiểu extended thì chương trình tính tổng y sẽ là như sau:
($e+, N+}
program Tong_5a;
uses crt;
var y:real;
n:byte;
Begin
clrscr;
y:= 0;
for n:= 1 to 50 do
y:= y + n/(n+1);
writeln('Tong y la:', y:0:18);
readln;
End.
b)
program Tong_5b;
uses crt;
var n:longint;
e, sh:real;
Begin
clrscr;
sh:=1/2;
n:= 2;
e:= 2 + sh;
while sh>= 2*1E-16 do
begin
inc(n);
sh:=sh*(1/n);
e:= e + sh;
end;
writeln('Gia tri e(n)la: ',e:10:6);
readln;
End.