Turbo Pascal 7.0 Repeat, While For, .
Repeat , .
Repeat:
Repeat
1;
2;
n;
until ;
, Repeat:
1) 1- n-, ;
2) , until; , ; , .
Repeat , . , , , .
Repeat , :
Program primer1_1;
Var a,b,tn,tk,dt,t,y:real;
f1,f2:text;
Begin
Assign (f1,primer1.dat);
Assign (f2,primer1_1.res);
Reset(f1);
Rewrite(f2);
Read(f1,a,b,tn,tk,dt);
t:=tn;
Repeat
If (t>=2)and(t<=2.6) then y:=a*t*t*sin(t)
else if t<2 then y:=exp(t*ln(a))+2*a
else y:=exp(b*t)*cos(t);
Writeln(f2,t=,t:4:2, y=,y:7:3);
t:=t+dt;
until t>tk;
close(f1);
close(f2);
end.
While , .
While:
While do ;
, , , While :
While do
begin
1;
2;
n;
end;
, While:
, While; , , ; , .
While , , .
While , :
Program primer1_2;
Var a,b,tn,tk,dt,t,y:real;
f1,f2:text;
Begin
Assign (f1,primer1.dat);
Assign (f2,primer1_2.res);
Reset(f1);
Rewrite(f2);
Read(f1,a,b,tn,tk,dt);
t:=tn;
While t<=tk do
begin
If (t>=2)and(t<=2.6) then y:=a*t*t*sin(t)
else if t<2 then y:=exp(t*ln(a))+2*a
else y:=exp(b*t)*cos(t);
Writeln(f2,t=,t:4:2, y=,y:7:3);
t:=t+dt;
end;
close(f1);
close(f2);
end.
|
|
For , .
For to downto, :
For := to do ;
For := downto do ;
. .
, For to:
1) ;
2) ; , , ; , .
, For to:
1) ;
2) ; , , ; , .
For .
For , :
Program primer1_3;
Var a,b,tn,tk,dt,t,y:real;
i,n:integer;
f1,f2:text;
Begin
Assign (f1,primer1.dat);
Assign (f2,primer1_3.res);
Reset(f1);
Rewrite(f2);
Read(f1,a,b,tn,tk,dt);
t:=tn;
n:=trunc((tk-tn)/dt)+1;
For i:=1 to n do
begin
If (t>=2)and(t<=2.6) then y:=a*t*t*sin(t)
else if t<2 then y:=exp(t*ln(a))+2*a
else y:=exp(b*t)*cos(t);
Writeln(f2,t=,t:4:2, y=,y:7:3);
t:=t+dt;
end;
close(f1);
close(f2);
end.
primer1.dat . , Read, . primer1.dat :
0.6 2.1 0 3.1 0.15
primer1_3.res .