begin
writeln;
writeln('start');
s := 0;
ok := false;
for i := 1 to inf do
begin
x := minus1(i)/fact(i+1);
writeln('iter=',i,' x=',x:11:8);
if i = 1 then s := x
else
begin
if abs(x) < del then
begin
ok := true;
break;
end
else s := s+x;
end;
end;
if ok then writeln('result=',s:12:8)
else writeln('no found!');
end.
Повернутися до відповідей
Мочалкин Блюз
18:40, 23.04.2014
program x20140423;
const
del: real = 0.0001;
inf = 20;
var
i: longint;
ok: boolean;
s, x, x1: real;
function minus1(var i: longint): longint;
var
j: integer;
m: longint;
begin
m := 1;
for j := 1 to i do m := m*(-1);
minus1 := m;
end;
function fact(i: longint): longint;
var
j: integer;
f: longint;
begin
f := 1;
for j := 2 to i do f := f*j;
fact := f;
end;
...см продолжение...
Мочалкин Блюз
1 18:41, 23.04.2014
begin
writeln;
writeln('start');
s := 0;
ok := false;
for i := 1 to inf do
begin
x := minus1(i)/fact(i+1);
writeln('iter=',i,' x=',x:11:8);
if i = 1 then s := x
else
begin
if abs(x) < del then
begin
ok := true;
break;
end
else s := s+x;
end;
end;
if ok then writeln('result=',s:12:8)
else writeln('no found!');
end.