Код моей проги:
Код
Program Lab3;
Uses CRT;
Function Choose(Text : String; a, b : Real) : Real;
Var
S : String;
Code : Integer;
V : Real;
X, Y : Byte;
Begin
Write(Text);
X := WhereX;
Y := WhereY;
repeat
GoToXY(X,Y);
ClrEoL;
Readln(S);
Val(S, V, Code);
until (Code = 0) and (V > a) and (V < b);
Choose := V;
end;
Function F(x : Real) : Real;
begin
f := ln(1 + x);
end;
Function Deg(n : Word; a: Real) : Real;
begin
if n <> 0 then
Deg := a * Deg(n - 1, a)
else
Deg := 1;
end;
Function Width(eps : Real) : Integer;
var
i, w : Integer;
begin
i := 1;
w := 0;
repeat
i := i * 10;
Inc(w);
until ( Trunc(1 / eps) div i = 0 );
Width := w;
end;
Function Bsum(x, e : Real; k : Integer) : Real;
var
i, j : Integer;
ak : Real;
begin
i := -1;
for j := 2 to k do
i := (-1) * i;
ak := i * Deg(k, x) / ( k * (k - 1) );
if (ak < e) then
Bsum := ak + Bsum(x, e, k + 1)
else
Bsum := ak;
end;
Var
Sn, rn : Real;
e, x : Real;
Begin
Repeat
ClrScr;
TextColor(yellow);
GoToXY(35,1);
Writeln('"""Program"""');
TextColor(white);
x := Choose(' - vvedite x(-1<x<2) : ', -1, 2);
e := Choose(' - vvedite eps(0<eps<0.5) : ', 0, 0.5);
Sn := (Bsum(x, 0.001, 2) + x) / (1 + x);
Writeln(' - Sn = ', Sn : 4: Width(e) );
rn := abs( f(x) - Sn );
Writeln(' - rn(x) = ', rn : 4: Width(e) );
TextColor(yellow);
Writeln('Prodolzim?(dlya vihoda nazmite klavishu Q)');
Until ReadKey in ['Q','q'];
Write('Goodbay...');
Readln;
Clrscr;
End.
Uses CRT;
Function Choose(Text : String; a, b : Real) : Real;
Var
S : String;
Code : Integer;
V : Real;
X, Y : Byte;
Begin
Write(Text);
X := WhereX;
Y := WhereY;
repeat
GoToXY(X,Y);
ClrEoL;
Readln(S);
Val(S, V, Code);
until (Code = 0) and (V > a) and (V < b);
Choose := V;
end;
Function F(x : Real) : Real;
begin
f := ln(1 + x);
end;
Function Deg(n : Word; a: Real) : Real;
begin
if n <> 0 then
Deg := a * Deg(n - 1, a)
else
Deg := 1;
end;
Function Width(eps : Real) : Integer;
var
i, w : Integer;
begin
i := 1;
w := 0;
repeat
i := i * 10;
Inc(w);
until ( Trunc(1 / eps) div i = 0 );
Width := w;
end;
Function Bsum(x, e : Real; k : Integer) : Real;
var
i, j : Integer;
ak : Real;
begin
i := -1;
for j := 2 to k do
i := (-1) * i;
ak := i * Deg(k, x) / ( k * (k - 1) );
if (ak < e) then
Bsum := ak + Bsum(x, e, k + 1)
else
Bsum := ak;
end;
Var
Sn, rn : Real;
e, x : Real;
Begin
Repeat
ClrScr;
TextColor(yellow);
GoToXY(35,1);
Writeln('"""Program"""');
TextColor(white);
x := Choose(' - vvedite x(-1<x<2) : ', -1, 2);
e := Choose(' - vvedite eps(0<eps<0.5) : ', 0, 0.5);
Sn := (Bsum(x, 0.001, 2) + x) / (1 + x);
Writeln(' - Sn = ', Sn : 4: Width(e) );
rn := abs( f(x) - Sn );
Writeln(' - rn(x) = ', rn : 4: Width(e) );
TextColor(yellow);
Writeln('Prodolzim?(dlya vihoda nazmite klavishu Q)');
Until ReadKey in ['Q','q'];
Write('Goodbay...');
Readln;
Clrscr;
End.