mn ơi giúp e giải bài này bằng pascal với ạ: Tính S(n) = x + x^2/2! + x^3/3! + ... + x^n/N!
2 câu trả lời
uses crt;
var i,n,x:word;
lt,gt:longint;
s:real;
begin
clrscr;
write('x=');readln(x);
write('n=');readln(n);
gt:=1;
lt:=1;
s:=0;
for i:=1 to n do
begin
lt:=lt*x;
gt:=gt*i;
s:=s+lt/gt;
end;
writeln(s:0:3);
readln;
end.
uses crt;
var n,i,lt,gt,x:longint; s:extended;
begin
clrscr;
readln(n);
readln(x);
lt:=1; gt:=1;
for i:=1 to n do
begin
lt:=lt*x;
gt:=gt*i;
s:=s+lt/gt;
end;
writeln('S(n) = ',s:0:2);
readln
end.