program tinh_ex;
var
x, ex, gt: real;
n, i: integer;
begin
write('Nhap vao so x: '); readln(x);
n := 10; (* so luong so hang *)
ex := 1; gt := 1;
for i := 1 to n do
begin
gt := gt * i; (* tinh giai thua i! *)
ex := ex + power(x, i) / gt; (* tinh tong theo cong thuc *)
end;
writeln('Gia tri cua e^', x, ' la: ', ex);
readln;
end.
program tinh_e;
var x: real;
n: integer;
s, t: real;
i: integer;
begin
write('Nhap x: '); readln(x);
write('Nhap n: '); readln(n);
s := 1; t := 1;
for i := 1 to n do
begin
t := t * x / i;
s := s + t;
end;
writeln('e = ', s);
end.
program Tinh_ex;
function TinhGiaiThua(n: Integer): Integer;
var i, giaiThua: Integer;
begin
giaiThua := 1;
for i := 1 to n do
giaiThua := giaiThua * i;
TinhGiaiThua := giaiThua;
end;
function TinhEx(x: Real; n: Integer): Real;
var i: Integer;
ex, phanTu: Real;
begin
ex := 1;
for i := 1 to n do
begin
phanTu := x / TinhGiaiThua(i);
ex := ex + phanTu; end;
TinhEx := ex;
end;
var x: Real;
n: Integer;
ketQua: Real;
begin
Write('Nhap gia tri cua x: ');
ReadLn(x);
Write('Nhap so luong phan tu n: ');
ReadLn(n);
ketQua := TinhEx(x, n);
WriteLn('Gia tri của ex la: ', ketQua:0:2);
end.