:
üREPEAT UNTIL
, , . WHILE . , , . begin ( repeat...until). . , , if, .
.
üBREAK
, , . , , GOTO. , , ,
üONTINUE
( FOR) .
@ 5.7. , Y (+,,/,*). Z . , Y=0 . (.. ). 0.
. . . ( ) , .. 1- . . . ( ) , . exp(x) ex, Borland. . , , . ( ). , ( ) . , ε.
5-7. ex <1. .
ex≈1+x+x2/2!+ x3/3!+ x4/4!+...
(). , r , i . 0,001. , , .
|
|
. .
5-8. Y=X2+Z 0≤X≤4 0≤Z≤ 10 1. , .. , . . ( ) ( Z). 1, for. , , . 11 Z.
/ =1 while.
@ 5.8. Y=X2+Z 0≤X≤4 1 1≤Z≤10 2.
@ 5.9. Y=X2+Z 0≤X≤4 0,5 1≤Z≤10 2.
@ 5.10. .
6.
, () () . . , N M ( NM ) () .
, .
, , . i Bij [I] B[I,J]. . .
. , (VAR) .
ü_: ARRAY [] OF _
,
VAR x,z: ARRAY [1..8] OF REAL;
y: ARRAY [5..10] OF INTEGER; b: ARRAY [1..4, 1..5] OF INTEGER;
X Z 8- ( 1 8) . Y 5- ( 5 10) , B .
- . , .
VAR i,j: INTEGER;
FOR i:=1 TO 8 DO BEGIN { }
WRITE('x[',i,']='); READLN(x[i]) END;
FOR i:=1 TO 4 DO { }
FOR j:=1 TO 5 DO BEGIN
WRITE('b[',i,j,']='); READLN(b[i,j]);
END;
FOR i:=1 TO 4 DO BEGIN { B}
FOR j:=1 TO 5 DO WRITE('b[',i,j,']=',b[i,j]:4:1,' ');
WRITELN { }
END;
X. , , [2]=, . (b[2,4]=) 4 5 . , . I , J. J , I ( I J 5 ). , : B[1,1], B[1,2],...B[1,5]; B[2,1],B[2,2],...B[2,5];...;B[4,1], B[4,2],...B[4,5], .. . , READLN WRITELN. . , . WRITE('b[',i,j,']= ',b[i,j]:4:1,' ') , , b[2,3]=25.3. WRITE , WRITELN , .
|
|
( ) ( const). :
CONST z:ARRAY [1..3] OF INTEGER=(4,5,2);
x: INTEGER=5;
r:ARRAY [1..3,1..2] OF INTEGER=((1,2),(3,4),(5,6));
Z : z[1]=4, z[2]=5, z[3]=2, : 5, R: r[1,1]=1, r[1,2]=2, r[2,1]=3, r[2,2]=4, r[3,1]=5, r[3,2]=6.
6-1. 10 . N=4 C=[5,2,7,4] . , . .
program P6_1; var i,n,m,k: integer; c: array [1..10] of integer; begin write('n='); readln(n); for i:=1 to n do begin write('i=',i:2,' c='); readln(c[i]); end; | n=4 | |||
m:=c[1]; k:=1; for i:=2 to n do if m<c[i] then begin m:=c[i]; k:=i end; writeln('m=',m:2,' n=',k:1); end. | m=5, k=1 i=2 5>2 | i=3 5<7 m=7,k=3 | i=4 7>4 | i=5 7, 3 |
6-2. . , N . . . ( ).
Program P6-2;
var n,i,j:integer; s,y,sr:real; x: array [1..10,1..5] of real;
Begin
readln(n); { ( 10)}
for i:=1 to n do; for j:=1 to 4 do begin { }
write(' ', i,'', j,'');
readln(x[i,j]);
End;
s:=0;
writeln(' ');
writeln(' I II III IV ');
for i:=1 to n do begin { }
y:=(x[i,1]+x[i,2]+x[i,3]+x[i,4])/4; { }
if y<=5000 then y:=1.05*y;
if (y>5000) and (y<=10000) then y:=1.1*y;
if y>10000 then y:=1.2*y;
x[i,5]:=x[i,4]+y; { }
writeln(i,x[i,1],x[i,2],x[i,3],x[i,4],x[i,5]);
s:=s+x[i,5];
End;
sr:=s/n;
writeln(' = ',s);
writeln(' = ',sr);
End.
N . i- ([i,1], [i,2], [i,3], [i,4]), . , X[i,5] , [i,4], Y=([i,1]+ [i,2]+[i,3]+ [i,4])/4 . , , 5000 5%, 10000 10%, 10000 20%. 1.05, 1.1 1.2 . , S , (S/N).
|
|
@
6.1. , , Y .
6.2. 1 , 2, . . Y, , .
6.3. -, ( ) : , , , . .
6.4. . =100000., , (). .
6.5. X[N,M]. , .
6.6. . M . 1 . N . . (. ) M=8, N=3. 1,4,7,3,8,6. 2 5 2→5→2. , 5. .
. .
6-3. X . . x(i) x(j) . , - x(i) , . i. (N=4), : 1,2,3,4: i=1 2,1,3,4; 3,1,2,4; 4,1,2,3; i=2 4, 2,1,3; 4, 3,1,2; i=3 4,3, 2,1. x[i]↔x[j] . , x[i]:=x[j]; x[j]:=x[i] . [i] [j], x[j]:=x[i] , [i] [j]. , [i], .
@
6.7. . , . , , . . .
6.8. . . [i]<[i+1] . . , .. N . , .
|
|
6.9. : , , , . .
6.10. , , . .. , , .
6.11. . ( , , ) .
6.12. . , . ( ) . , , . . , , .. .
6-4. A(N,N) (.. 1,2,3, ..), , . 6.4. , . .
, , , :
1). , - ;
2). , - ;
3). - ;
4). - .
A(1,1). . 6.4.
. ST ( N, A(N,N)), KL ( N), K ( 1). (while k<n*n) K N*N, N. , (. ) . if/else if, , . IF while, . , .. ( A(1,1)), A .
Program P6-4;
Uses crt;
var n,i,j,st,kl,k:integer;
a:array [1..10,1..10] of integer;
Begin;
Clrscr;
write( ( 10)); readln(n);
st:=n; kl:=n; k:=1; { , }
a[st,kl]:=k; { a(n,n) 1}
{ - }
while k<n*n do begin
{ 1 }
if (kl=n) and (st>1) then begin st:=st-1; k:=k+1; a[st,kl]:=k;
while (st<n) and (kl>0) do begin st:=st+1; kl:=kl-1; k:=k+1; a[st,kl]:=k end; { -}
End
{ 1 }
else if (kl>1) and (st=n) then begin kl:=kl-1; k:=k+1; a[st,kl]:=k;
while (st>1) and (kl<n) do begin st:=st-1; kl:=kl+1; k:=k+1; a[st,kl]:=k end; { -}
End
{ 1 }
else if (kl>1) and (st=1) then begin kl:=kl-1; k:=k+1; a[st,kl]:=k;
while (st<n) and (kl>1) do begin st:=st+1; kl:=kl-1; k:=k+1; a[st,kl]:=k end; { -}
End
{ 1 }
else if(kl=1) and (st>1) then begin st:=st-1; k:=k+1; a[st,kl]:=k;
while (st>1) and (kl>0) do begin st:=st-1; kl:=kl+1; k:=k+1; a[st,kl]:=k end; { -}
|
|
End;
End;
writeln(' ');
for i:=1 to n do begin for j:=1 to n do write(a[i,j]:4); writeln; end;
End.
, , . CHAR . STRING. , var ST: char; SM: string[32]; SS: string. ST , SM 32 . , 255 . , : ST:=a; SM:=;. .
concat (1, 2) | 1 2 (: concat('','')='') |
copy(, , ) | , (: copy('',4,5)='') |
delete(, , ) | , (: delete('',4,4)='') |
insert(1, 2, ) | 1 2, (: insert(' ',' ',9)=' ') |
length() | (: length('')=4) |
pos(1, 2) | 2 1 , (: pos('','')=2) |
upcase() | |
str(, , ) | integer real ( ) (: str(5,x) ='5', str(18.3:5:2,y) y='18.30') |
val(, , ) | , , =0 (: val('12.4',x,k) x=12.4, k=0) |
ord() | ASCII- (: ord()=159) |
chr() | ASCII- (: chr(159)='') |
+ ( concat) . : += .
7-1. = Y. : 1). n=7, 2). (.. ) Y. 3). Y . .
y:=copy(x,pos(' ',x)+1,length(x))+' '+copy(x,1,pos(' ',x)-1);
7-2. K . , +1. P7_2 . , , . . (j ). , ( i- ). () .
0..32 | |
65..90 | A..Z |
97..122 | a..z |
128..159 | .. ( ) |
160..175 | .. ( ) |
224..239 | .. |
240,241 | , |
. ( 0 255) ASCII-. 128 , , . 0..31 ( , ..). A..Z 65..90, a..z 97..122. 128 . A.. 128..159, a.. 160..175, .. 224..239, 240, 241. , a.. 32, .. 80. , 256 . , : #. , write(#65,#177,#201,#205,#187); : A ▒╔═╗ . , , , : for i:=0 to 255 do write(chr(i),i:3,' ');. , 0 31 , , . . 0 . ( ). : <; =; > ( ); ߒ<ߒ ( , ˒<C); >ETP ( ).
7-3. S ( ), . S . D. , S . D= 'xyz123ABC'. X:=chr(ord(x[1])-32). ord(x[1]) , 32 (.. ), , , .
Program P7_3;
var x:string[1]; d:string; i:integer;
const s:string='xyz123ABC'; { }
Begin
d:='';
for i:=1 to length(s) do begin { S}
x:=copy(s,i,1); { }
{ ''<=<='', 32}
if (x>='')and(x<='') then x:=chr(ord(x[1])-32);
{ ''<=<='', 80}
if (x>='')and(x<='') then x:=chr(ord(x[1])-80);
{ }
if x<'' then x:=upcase(x[1]);
d:=d+x; { D}
End;
write(d); {: 'XYZ123ABC' }
End.
@
1. (, ) .
2. .
3. .
4. .
5. .
6. .
7. .
8. .
9. ≤N, . X , N . .
10. , , , ( .., ). .
11. ( 1000 .) (, 103= ).
12. ( ). , . , , .
13. ( , ), . . Y.
14. : , , . . , 8- , ( ).
15. , , . . 240 241, .. , , . , , / /.
16. , ( 1900..2100) . .., 06.04.2002. : 4. , 4 (, 1800, 1900, 2100).
17. , ( 1900..2100) , . , .
18. , (1900..2100), , .
. . : , , , . , , , . ( ) , (record). , Vr ( ). - , . Var .
(). Vr, : tab, im, tarif, dn . Var () : X Y. , (.), x.tarif, x.im. : y[3].tarif. .
type vr=record { }
tab: integer; {}
im: string[4]; {}
tarif, dn: real
End;
var x:vr; y:array [1..5] of vr;
( ). : . , , , . ( String), . :
1. . , .
: []: file of [];
: A: file of string[80]; F1: file of char; F2: file of real;
2. . .
: []: text;.
: f3: text;
, . ( record). , .
, . :
assign(, ) | (). |
reset() | . |
rewrite() | . |
close() | . |
erase() | ( ). |
eof() | (True, ). |
:
read(f,x1,x2,xn) readln(f,x1,x2,xn) 1,2,,xn f.
write(f,x1,x2,xn) writeln(f,x1,x2,xn) 1,2, n f.
:
append() | . |
eoln() | (True, ). |
read(,) | . |
readln(,) | , . |
write(,) | . |
writeln(,) | , . |
:
filesize() | . |
filepos() | . |
seek(,) | . |
truncate() | . |
. , , , ( ) . . . , .. .
9-1.
). y=x/2 x=0,0.5,1.0, 4 func. , , . . txt , TotalCommander ( txt ). func.txt, f, .
). C func.txt .
program 9_1a; { }
var f:text; { f}
x,y:real;
Begin
{ f func.txt}
assign(f,'func.txt');
rewrite(f); { f }
x:=0;
while x<=4 do begin { }
y:=x/2; x:=x+0.5;
writeln(f,x:3:1,y:4:1); { }
End;
close(f); { }
End.
program 9_1b; { }
var f:text; { f}
x,y:real; i:integer;
Begin
assign(f,'func.txt');
reset(f); { }
for i:=1 to 9 do begin
read(f,y,x); { }
{ , }
writeln('y=',y:3:1,' x=',x:4:1);
End;
close (f); { }
End.
9-2. . ( record) VIR (. 9.1).
Vir | Ved | |||||||
tab | im | tarif | dn | im | zar | nalog | vid | |
. | 9.1 |
: tab, im ( 4- ), tarif , dn. . VED, im, zar (=tarif*dn), nalog (=13%*zar) vid (=zar-nalog). . . Vvod : 1). Vir. 2). Vir V. 3). R. 4). R Ved. Vivod : ( ).
program Vvod; { 9-2}
Uses crt;
const n=3;
type vr=record { }
tab: integer; {}
im: string[4]; {}
tarif, dn: real;
End;
vd=record { }
im: string[4];
zar, nalog, vid: real;
End;
var vir: file of vr; { }
ved: file of vd; { }
v: array[1..n] of vr; { V }
r: array[1..n] of vd; { R }
I: integer;
Begin
Clrscr;
{ }
assign(vir,'vir'); assign(ved,'ved');
rewrite(vir); { Vir }
writeln('!');
writeln(', , , ');
for i:=1 to n do begin
readln(v[i].tab); readln(v[i].im);
readln(v[i].tarif); readln(v[i].dn);
writeln(v[i].tab:2, v[i].im:6, v[i].tarif:3:0, v[i].dn:4:0);
write(vir,v[i]); { Vir }
End;
reset(vir); { Vir }
rewrite(ved); { Ved }
for i:=1 to n do begin {}
read(vir,v[i]); { Vir}
r[i].im:=v[i].im; r[i].zar:=v[i].tarif*v[i].dn;
r[i].nalog:=0.13*r[i].zar; r[i].vid:=r[i].zar-r[i].nalog;
write(ved,r[i]); { Ved}
End;
reset(ved); { Ved }
for i:=1 to n do begin {}
read(ved,r[i]); { Ved}
writeln(r[i].im:4, r[i].zar:5:0, r[i].nalog:7:2, r[i].vid:8:2);
End;
close(ved);close(vir); { }
End.
program Vivod; { 9-2}
Uses crt;
const n=3;
Label m;
Type
vd=record { }
im: string[4];
zar, nalog, vid: real;
End;
var ved: file of vd; { }
r: array[1..n] of vd; { R }
xz,xn,xv:real; {: , , }
I: integer;
x:string[4]; { }
Begin
Clrscr;
assign(ved,'ved.txt');
write(' (0) ()? '); readln(x);
writeln(' ');
reset(ved); { Ved }
if x='0' then begin { }
for i:=1 to n do begin
read(ved,r[i]); { Ved}
writeln(r[i].im:4, r[i].zar:9:0, r[i].nalog:7:2, r[i].vid:8:2);
{ }
xz:=xz+r[i].zar; xn:=xn+r[i].nalog; xv:=xv+r[i].vid;
End;
writeln('',xz:9:0,xn:7:2,xv:8:2) { }
End;
if x<>'0' then begin { }
for i:=1 to n do begin
read(ved,r[i]);
if x=r[i].im then begin { - }
writeln(r[i].im:4,r[i].zar:9:0, r[i].nalog:7:2, r[i].vid:8:2);
goto m { }
End;
End;
writeln(' : ',x);
M:end;
Close(ved)
End.
9-3. , ( ), Rab1, Rab2, Rab3. , Tarif. Ved , .
Tarif | Rab1 | Rab2 | Rab3 | ||||||||||
tb | im | tr | tb | ch | tb | ch | tb | ch | |||||
MT | MR | ||||||||||||
tb | im | tr | tb | ch | |||||||||
Ved | |||||||||||||
tb | im | ch | zr | nl | vd | ||||||||
390,0 | 2610,0 | ||||||||||||
130,0 | 870,0 | ||||||||||||
227,5 | 1522,5 | ||||||||||||
390,0 | 2610,0 | ||||||||||||
78,0 | 522,0 | ||||||||||||
1215,5 | 8134,5 | . | 9.2 | ||||||||||
:
1. Rab1, Rab2, Rab3 Tarif.
2. Mr[1..15].
3. ( mr.tb). ( ) .
4. Tarif Mt[1..6]. , , Ved.
5. Ved .
9.2. , .
Vedom . Rab1, Rab2, Rab3, Tarif .
program VEDOM; { 9-3}
Uses crt;
type { }
rab=record tb,ch:integer end; { }
tar=record tb,tr:integer; im:string[4] end; { }
{ }
ved=record tb,ch,zr:integer; im:string; nl,vd:real end;
var { , }
r1,r2,r3:file of rab; { }
{ }
mr:array [1..15] of rab;
x: rab; { Rab, }
t:file of tar; { }
{ }
mt:array [1..6] of tar;
v:file of ved; { }
mv:ved; { }
{ }
sch,szr:integer; snl,zvd:real;
m,i,j,k:integer;
Begin
Clrscr;
{-------------------- Rab1-3 MR---------------------------}
assign(r1,'rab1'); assign(r2,'rab2'); assign(r3,'rab3'); reset(r1); reset(r2); reset(r3);
k:=0;
while not eof(r1) do begin k:=k+1; read(r1,mr[k]) end;
while not eof(r2) do begin k:=k+1; read(r2,mr[k]) end;
while not eof(r3) do begin k:=k+1; read(r3,mr[k]) end;