Разработка и реализация программ с циклической структурой, страница 5

С циклом while.

С циклом repeat until

1)  С циклом for.

Program lab3_2;

uses CRT;

var x, y,:real;

 i, n:integer;

const a=-1;

          b=1;

          h=0.2;

          eps=0.000001;

begin

clrscr; n:=Trunc((b-a)/h)+1; writeln(’------------------’); writeln(’| x |   y   |’);

writeln(--------------------);

for i:=0 to (n-1) do

begin

x:=a+i*h;

if (cos(x)<>eps) and (x>eps) and (x<>1) then

begin

y:=sin(x)/cos(x)/ln(x);

writeln (’| ’, x:4:1,’ |    ’, y:4:5,’     |’);

end

else

writeln (’| ’, x:4:1,’ | не существует |’);

end; writeln (’---------------------------------’);

readln;

end.

2)  С циклом while.

Program lab3_2;

uses CRT;

var x, y,:real;

 i, n:integer;

const a=-1;

          b=1;

          h=0.2; eps=0.000000001;

begin

clrscr; writeln(’-------------------------’); writeln (’|  x  |     y     |’);

writeln(’-----------------------------’); n:=Trunc((b-a)/h)+1;

i:=0;

while i<=(n-1) do

begin

x:=a+i*h;

if (cos(x)<>eps) and (x>eps) and (x<>1) then

begin

y:=sin(x)/cos(x)/ln(x);

writeln (’| ’, x:4:1,’ |    ’, y:4:5, ’     |’);

end

else

writeln (’| ’, x:4:1,’ | не существует |’);

i:=i+1;

end;

writeln(’--------------------------’); readln;

end.

3)  С циклом repeat until.

Program lab3_2;

uses CRT;

var x, y,:real;

 i, n:integer;

const a=-1; b=1; h=0.2;eps=0.000000001;

begin

clrscr; writeln(’-------------------’); writeln(’|  x  |     y     |’);

writeln(-------------------------); n:=Trunc((b-a)/0.2)+1;