Код
Вначале создан Юнит
Unit Iterate;
interface
Uses crt, Graph;
Var a,i,b,k,Err,x0,y0,x1,y1,m,w,x3,y3,x2,y2:integer;
x,y,s:extended;
procedure Init_Graph;
function iterative(x:real):real;
function recursive(a,x,b:extended):extended;
procedure gra;
Implementation
procedure Init_Graph;
var GD, GM, EC: Integer;
begin
GD:= Detect;
InitGraph(GD,GM,'C:\Program Files\Turbo_Pascal\BGI\');
EC:= GraphResult;
if EC<>GrOK then
begin
WriteLn('Error Graphic Initialize: ', GraphErrorMsg(EC));
Halt(1);
end;
end;
function iterative(x:real):real;
var a,b:real;
begin
a:=x; s:=0;
b:=1;
while abs(a/b)>0.001 do
begin
s:=s+a/b;
a:=a*(-x*x);
b:=b+2;
end;
iterative:=s;
end;
function recursive(a,x,b:extended):extended;
begin
if abs(a/b)>0.01 then
recursive:=recursive(a*(-x*x),x,b+2)+(a/b)
else recursive:=0;
end;
procedure gra;
begin
x0:=200;
y0:=250;
m:=150;
w:=150;
SetColor(2);
{coord.line.x}
Line(0,450,639,450);
{arrows x}
Line(639,450,629,445);
Line(639,450,629,455);
{coord.line.y}
Line(200,0,200,479);
{arrows y}
Line(200,0,205,10);
Line(200,0,195,10);
{text.x;text.y}
OutTextXY(210,5,'Y');
OutTextXY(630,435,'X');
OutTextXY(205,455,'0');
OutTextXY(50,455,'-1');
OutTextXY(350,455,'1');
SetLineStyle(3,0,1);
Line(350,450,350,50);
Line(50,455,50,50);
SetColor(2);
SetLineStyle(0,0,0);
Rectangle(380,120,385,125);
OutTextXY(390,120,'Function y=arctan(x)');
SetColor(4);
Rectangle(380,140,385,145);
OutTextXY(390,140,'Iterative');
SetColor(5);
Rectangle(380,160,385,165);
OutTextXY(390,160,'Recursive');
SetColor(2);
OutTextXY(390,180,'for next - press ENTER');
readkey;
x:=-1;
while x<=1 do
begin
y:=arctan(x);
x1:=Round(x0+x*w);
y1:=Round(y0-y*m);
PutPixel(x1,y1,2);
x:=x+0.001;
end;
readkey;
x:=-1;
while x<=1 do
begin
x2:=Round(x0+x*w);
y2:=Round(y0-iterative(x)*m);
PutPixel(x2,y2,4);
x:=x+0.001;
end;
readkey;
x:=-1;
while x<=1 do
begin
x3:=Round(x0+x*w);
y3:=Round(y0-recursive(x,x,1)*m);
PutPixel(x3,y3,5);
x:=x+0.001;
end;
readkey;
{end.else.point.}
end;
End.
Затем главная программа
program individualka;
Uses Crt,Graph,Iterate;
Var a,b,i,k,Err,x0,y0,x1,y1,m,w,x2,y2,x3,y3:integer;
x,y,s:extended;
Begin
clrscr;
x:=-1;
write('|| X || Iterative || Recursive || Arctg ||');
writeln('');
while x<=1.1 do
begin
if x>0 then TextColor(Red) else
TextColor(Green);
writeln('|| ',x:3:2,' || ',iterative(x):3:2,' || ',recursive(x,x,1):3:2,' || ', arctan(x):3:2,' ||');
x:=x+0.1;
end;
Textcolor(Green);
writeln('');
write('press any key for graphics drawing...');
readkey;
Init_Graph;
gra;
readkey;
CloseGraph;
End.
Товарищи, если не тяжело, помогите. Нужно написать эту же программу на С. Желательно, без изменений.
Заранее благодарна.