Вы находитесь на странице: 1из 104

..

PDF created with pdfFactory Pro trial version www.pdffactory.com

1.
.

- , ,
- .
.
, -
, ,
.
.
, ,
- ,
.
:

.
.
,
,
.

( ).

.
,
( ).

.
1984 . .
1968-1970 ..,
.

Turbo Pascal 7.0 :


) ;
) ( );
)
;
) ;
) .

PDF created with pdfFactory Pro trial version www.pdffactory.com

3
, :
TURBO.EXE,
( ,
, , );
TURBO.TPL - ;
TURBO.HLP - .

Turbo Pascal 7.0 :


1. 7 .
2. turbo.exe
:
1. .
2. , , .
3. ,
.

[ F10]

.
F1 - ;
F2 - ;
F3 - ;
F9 - , ;
F10 - ;
CTRL-F9 - (
);
ALT-F5 - ;
Esc - .
ALT-X - .

PDF created with pdfFactory Pro trial version www.pdffactory.com

2. . .

.
- ,
.
3 :
1.
;
2. - 0..9
3. - (+,-,*,/,=,<,>,<>,<=,>=,.:;{} := ( ) ),
: and, begin,const,div,do,else,for, ..
.
- , ,

. , .
-
,
.
()
.

.
, ..

.
: Zap, gor,X, p1, summa, a28,rar_1, proba, x1,y1,max,min
..

ShortInt
Integer


-128...127
-32768 ...32767

PDF created with pdfFactory Pro trial version www.pdffactory.com

5
Longint

Byte
Word
Real
Single
Double
Extended
Comp

Boolean
Char

String
array
record
set
file
pointer

-2147483648 ...
2147483647
0 .... 255
0 ... 65535
2,9 10-39..... 1,7 1038
11..12
7..8
15..16
19..20
19..20
TRUE
FALSE
1
,
256 .

PDF created with pdfFactory Pro trial version www.pdffactory.com

3. .
-.
.

( := ).
:=


.
!!!
: =2;

2
=+2;


abs(x)
exp(x)
sin(x) cos(x)
arctan(x)
ln(x)
sqr(x)
sqrt(x)
random(x)
Pi
odd(x)

, ..
.
,
.
.
(>0)
.
.

0<=...< x
.
true, ,
false .

PDF created with pdfFactory Pro trial version www.pdffactory.com

7
inc(x,n)
dec(x,n)
int(x)
frac(x)
trunc(x)
round(x)

n.
n.
.
.
longint.

.


.
1. , ,
.
.
2.
.
3. - . ( [{
)
4. 2 .
5.
:
1) ;
2) * / DIV ( )
MOD ( )
3) + .
1. .
2.
.
3. : ,
.

PDF created with pdfFactory Pro trial version www.pdffactory.com

8
:
ax2 + bx + c
b

4 ac

a + c 2b
3 x

a*x*x +b*x + c

sqrt(b*b 4*a*c)

(a + c 2*b)/(3-x)

:
:
VAR a,b : integer;
r,s : integer;
............................
r:=a div b;
{r=3 a=7, b=2}
r:= a mod b; {r=1 a=7,b=2}
s:=a*b;
s:=a div b;
:
VAR a,b : integer;
r : integer;
r:=a/b; { ,
}
VAR a,b : real;
r : integer;
.................
r:=a div b; { div
}
r:=a mod b; { mod
}
VAR a,b : integer;
r : real;
....................

PDF created with pdfFactory Pro trial version www.pdffactory.com

9
r:=a div b; {r }

.
VAR a : integer;
b : real;
c : real;
...........
c:=a+b {}
a:=c+b; {}

.
Read(< >);
Readln(< >);

. ,
,
Enter. <
> .
Ln Read ,
.
,
.
READLN(f,b,a);
read(s);
readln(w);
.
Write(, <>);
Writeln( - , <>);
< > .

PDF created with pdfFactory Pro trial version www.pdffactory.com

10

Write.
.
Write(y:5:2) y 5 , 2
.
Writeln(y=,y:8:3) - , 3.
Writeln(=,:4) - , 4
.

4. .
(* *)
PROGRAM < >;
USES - ;
{ }
LABEL - ;
CONST - ;
TYPE - ;
VAR - ;
PROCEDURE - ;
FINCTION - ;
{ }
BEGIN
,

END. { ,
}
.
Var,
,
.

PDF created with pdfFactory Pro trial version www.pdffactory.com

11
,
Var f,a : integer;
g,y1,y2 : real;
s,s1,s2 : char;
CONST.
:
onst n=25; r=38;
m=5.15;

.
1 : ,
, , ,
.
.
, ,
.
program exampl_1;
var a,b : integer;
begin
writeln(' );
readln(a);
writeln(' );
readln(b);
writeln('A+B= ', a+b:5);
writeln('A-B= ', a-b:5);
writeln('A*B= ', a*b:7);
writeln('A div B= ', a div b:5);
writeln(' <Enter>');
readln;
end.

PDF created with pdfFactory Pro trial version www.pdffactory.com

12
.
, , :
Enter, Save as...
Enter;
Enter;

Compile
Enter;

ALT-F9.
.

RUN
Enter;

CTRL-F9.

1. .
2. .
3. .
4. .
5. .
6. .
.

.
:

PDF created with pdfFactory Pro trial version www.pdffactory.com

13
( ,
),
-
;
( ).
2 :
.
program examp2_1;
var a, z1,z2,z3, rez : integer;
begin
writeln(' ); readln(a);
z1:=a Mod 10;
writeln(' - z1);
z2:=(a Div 10) Mod 10;
writeln(' - z2);
z3:=a Div 100;
writeln(' - z3);
rez:=z3*100+z2*10+z1;
writeln(' - rez);
end.

1.
2.

3.

4.
5.

.
3476589. ,
.
- . ,
Error 106: Invalid numeric
format.
Writeln. ,
,
Error 8: String constant exceeds line.

exampl2_1
. exampl2_2.

exampl2_2
. exampl2_3.
: .
:) ;

PDF created with pdfFactory Pro trial version www.pdffactory.com

14
) , .

5. .


, ,
. :
begin
; ;...;
end;
BEGIN END.
,
BEGIN-END .
- ,

, .
if

.
:
if<> then <1>
else <2>
.
ELSE IF.
,
THEN ELSE
.

PDF created with pdfFactory Pro trial version www.pdffactory.com

15
!!!! ELSE
.
IF..THEN...ELSE
.

, ,
(>,<,>=,<>,<=).
,
: OR() NOT() AND ().
.
IF... THEN... ELSE
1. : ,
IF.
2. , .. ,
, THEN,
,
IF ...THEN...ELSE.
3. IF (..
), ,
ELSE,
IF...THEN...ELSE .

PDF created with pdfFactory Pro trial version www.pdffactory.com

16
1:
.
PROGRAM prim1;
USES Crt;
var x,y : real;
begin
ClrScr; (* *)
Writeln( );
Readln(x,y);
IF x>y THEN Writeln(x)
ELSE Writeln(y);
end.
:
if<> then <>
,

IF...THEN... .

PDF created with pdfFactory Pro trial version www.pdffactory.com

17
2 :
.
.
PROGRAM prim2;
USES Crt;
var x,y ,max : real;
begin
ClrScr; (* *)
Writeln( );
Readln(x,y);
max:=x;
IF y>max THEN max:=y;
Writeln(max);
end.

THEN , ELSE.

BEGIN END.
1. If <> then
begin
1;
2;
...................
n;
end
else ;
2. If <> then
else begin
1;
2;
...................
n;
end;

PDF created with pdfFactory Pro trial version www.pdffactory.com

18
3. If <> then
begin
1;
2;
...................
n;
end
else
begin
1;
2;
...................
n;
end
3.
ax2 + bx +c = 0
:
1. a,b,c.
2. .
3. ,
, .
program kvyr;
var a,b,c : integer;
x1,x2,d : real
begin
writeln( - );
read(a,b,c);
d:=b*b-4*a*c;
if d>=0 then begin
x1:=(-b+sqrt(d))/(2*a);
x2:=(-b-sqrt(d))/(2*a);
writeln( x1=,x1, x2,x2)
end

PDF created with pdfFactory Pro trial version www.pdffactory.com

19
else if d=0 then writeln(x1=x2=,-b/(2*a))
else writeln( );
end.
4.

) max(x+y+z, xyz) + 3
) min(x2+y2, y2+z2) - 4
a, b, c
program kvyr;
var a,b,c : integer;
d=b2 4ac
x1,x2,d : real
begin
writeln(
- );

read(a,b,c);
d>0
d:=b*b-4*a*c;
d>=0 then begin
x1= if(-b+d)/(2*a)

x1:=(-b+sqrt(d))/(2*a);
d=0
x2:=(-b-sqrt(d))/(2*a);
writeln(
x2= (-b-d)/(2*a)
x1=x2=-b/2ax1=,x1, x2,x2)
end
else if d=0 then writeln(x1=x2=,-b/(2*a))
x1, else
x2 writeln(x);
end.

4.
) max(x+y+z, xyz) + 3

) min(x2+y2, y2 +z2) - 4

6.


()


.
- - .

PDF created with pdfFactory Pro trial version www.pdffactory.com

20
, , .
3 :
1)
2)
3)


- : 2
1 10 .
?
. ,
,
. ,
,
,
(
),

.
2 :
2 i = , i 1 10, - 2 20.
,

.
,
.
FOR K:=M1 TO M2 DO
1
FOR K:=M1 TO M2 DO
BEGIN
1;
.......................
n;
END;
FOR K:=M1 DOWNTO M2 DO
BEGIN

PDF created with pdfFactory Pro trial version www.pdffactory.com

21

END;
- , 1 2 -
. DOWNTO
-1.
!
1)
.
2) , , ..
K= .
3) ,
( )
.
4) ,
.
5)
, .. =M2

- FOR
k=M1, M2

1: 10 20.
PROGRAM N1;
VAR i: integer; { }
a: integer;
BEGIN
FOR i:=10 TO 20 DO

PDF created with pdfFactory Pro trial version www.pdffactory.com

22
BEGIN
a:=i*i;
writeln( ,i,=,a);
END
END.

FOR i:=10 TO 20 DO writeln( ,i,=,i*i);

i=10, 20

a=i*i

,i,=.a

2. 40 10.
PROGRAM N2;
VAR i: integer; { }
BEGIN
FOR i:=40 DOWNTO 10 DO
write(i, )
END.

PDF created with pdfFactory Pro trial version www.pdffactory.com

23

7.
1. .
12 , .
PROGRAM summa;
VAR a: integer; { }
i: integer; { }
S: integer; {}
BEGIN
S:=0;
FOR i:=1 TO 12 DO
BEGIN
writeln( );
readln(a);
S:=S+a
END;
writeln( =,S);
END.
2.
.
10,
.
PROGRAM kol;
VAR a: integer; { }
i: integer; { }
K : integer; { }
BEGIN
K:=0;
FOR i:=1 TO 10 DO
BEGIN
write( a: );
readln(a);
IF a<0 THEN K:=K+a
END;
IF K=0 THEN writeln( )

PDF created with pdfFactory Pro trial version www.pdffactory.com

24
ELSE writeln( ,K:4);
END.
3. , 3,
.
PROGRAM summa;
VAR a: integer; { }
i: integer; { }
S: integer; {}
K: integer; { 3}
BEGIN
S:=0; K:=0;
FOR i:=1 TO 10 DO
BEGIN
write( )
readln(a);
IF a mod 3=0 THEN
begin
K:=K+1;
S:=S+a;
end
END;
IF K=0 THEN writeln( 3 )
ELSE writeln( 3 =, S:6)
END.
4. n!.
n!=1*2*3*...*n. 0!=1
PROGRAM N;
VAR F: integer;
i: integer;
BEGIN
F:=1;
FOR i:=1 TO 15 DO
F:=F*i;
writeln(15! =,F)
END.

PDF created with pdfFactory Pro trial version www.pdffactory.com

25
5. n.
PROGRAM step;
VAR a: integer; {}
n:integer; { }
i: integer; { }
W: integer; {}
BEGIN
write( ); readln(a);
write( n); readln(n);
W:=1;
FOR i:=1 TO n DO
W:=W*a;
writeln(a, ,n, ,W:6)
END.
: 1! + 2! + 3! + ... + n!, n=5
.......
s:=0; F:=1;
For i:=1 to 5 do
begin
f:=f*i;
s:=s+f;
end;

8. WHILE
WHILE ,
,
.
:
WHILE < - / > DO
BEGIN

END

PDF created with pdfFactory Pro trial version www.pdffactory.com

26
WHILE ( ) DO ( )
.
.
, .
. ,
(EXIT, GOTO)
.
.
,
, ,
, .
WHILE
.
: a:=1;
n:=1;
WHILE 2-a<=3-n+1 DO
BEGIN
a:=a+2;
n:=n+1
END;

PDF created with pdfFactory Pro trial version www.pdffactory.com

27

1. , 100.
PROGRAM N;
var k:integer;
s:integer;
begin
s:=0; k:=0;
while s<=100 do
begin
k:=k+1;
s:=s+k
end;
writeln( =,k);
end.
2. 10 30.
PROGRAM N;
var k:integer; { }
s:integer; {}

PDF created with pdfFactory Pro trial version www.pdffactory.com

28
begin
s:=0; k:=10;
while k<=30 do
begin
s:=s+k;
k:=k+2
end;
writeln( 10 30=,s);
end.

3. y=4x2 - 2x + 3,
x, -4 2 0.5
PROGRAM N;
var x:integer;
y:real;
begin
x:=-4;
while x<=2 do
begin
y=4*x*x-2*x+3;
x:=x+0.5
end;
writeln( x=,x, y=,y:8:3);
end.

PDF created with pdfFactory Pro trial version www.pdffactory.com

29

9. Repeat
WHILE ,

. .

REPEAT

UNTIL < >

PDF created with pdfFactory Pro trial version www.pdffactory.com

30
REPEAT

.
!
1. .
2. .
1. ,
81.
Program n;
var k:integer; {}
s:integer; {}
begin
k:=1; s:=0;
REPEAT
s:=s+k*k;
k=k+1
Until k>81;
writeln( =,s)
end.
2. Y=X2, =8; 6; 4 ;2
=8;
REPEAT
Y:=X*X; writeln(x:3, y:5); X:=X-2
UNTIL X=0
3. ,
(
).
Program ex3;
Var a: integer; { }
s: integer; {}
Begin
s:=0;
a:=0; { }
REPEAT
s:=s+a;
readln(a)

PDF created with pdfFactory Pro trial version www.pdffactory.com

31
UNTIL a<0;
Writeln(s);
End.

4. () . , .
: b, b
(, b)=(b, r), r - b .
r= a mod b=a- (a div b)*b
, =48, b=18.
A
b

48
18
48 mod 18 = 12
18
(48,18)=(12,18)
12
18 mod 12 = 6
(12,18)=(12,6)
12 mod 6 = 0
6
(12,6)=(0,6)
0
6
(0,6)=6
Program NOD;
var a,b:longint;
begin
writeln( );
readln(a,b);
REPEAT
if a>b then a:=a mod b else b:=b mod a
UNTIL (a=0) or (b=0);
writeln(=, a+b);
readln;
end.
.
,
.

PDF created with pdfFactory Pro trial version www.pdffactory.com

32

10. .

1 : n (n<=9999). ,
(),
. , : 2222, 6116, 0440.
, ,
For 1 4. m ,
. r
- .
: r:=10*r + m Mod 10 m:=m Div 10.
.
i
m
r
3994
0
1
399
0*10+3994 mod 10= 0+4=4
2
39
4*10+399 mod 10=40+9=49
3
3
49*10+39 mod 10=490+9=499
4
0
499*10+3 mod 10=4990+3=4993
Program ex1;
Var n,m,r,i : Integer;
Begin
writeln( ,
readln(n);
m:=n; r:=0;
For i:=1 to 4 do
begin
r:=r*10+m mod 10; m:=m Div 10;
end;
if r=n Then Writeln();
Else Writeln();
readln;
end.

10000);

1) ,
Longint.

PDF created with pdfFactory Pro trial version www.pdffactory.com

33
2) for, , While
Until

Repeat ...

2 : n .
.
: .
10, ..
m - , - .
Program ex2;
var m,n : Longint;
k : Integer;
begin
writeln( );
readln(n);
m:=n; k:=0;
While m<>0 Do
begin Inc(k); m:=m Div 10 end;
writeln ( ,n, - ,k, );
end.

2, :
;
;
;
;
;
, 5;
,
.
3 : ,
1 . 1
. :
2,3,5,7,11,13, 17, 19, 23, ....

PDF created with pdfFactory Pro trial version www.pdffactory.com

34
3 ,
. n 2 n div 2,
2 n
program ex3;
Var i, n :Longint;
Begin
Writeln( );
Readln(n);
i:=1;

Repeat
inc(i)
Until (i>n div 2) or (n mod i = 0);
if i> n div 2 Then Writeln( ,n,);
lse Writeln( ,i,-
, n, , 1);
end.

While.
. ,
n
. Repeat....Until
, i>n div 2,

if n mod i = 0 Then Writeln(....,i)

11.
ase < > of
< 1>: < 1>;
< 2>: < 2>;
......
< n>: < n>;
[Else < >; ]
end;

, .

PDF created with pdfFactory Pro trial version www.pdffactory.com

35
.
,
, Else, ,
, End.
1: , ,
- -
.
:
:
;
;
, .
Program 4;
var ch : char;
begin
Writeln( );
Readln(ch);
Case ch of
a,e,i,o,u : writeln( );
a...z : Writeln( );
else writeln( );
end;
end.

2.
: -1, -2, -3, -4.
m (1m4)
.
Program mast;
var m:integer;
begin
write( ); readln(m);
case m of
1 : writeln();
2 : writeln();
3 : writeln();
4 : writeln()

PDF created with pdfFactory Pro trial version www.pdffactory.com

36
else writeln( );
end;
end.

12.

, ,
- .
:
;
;
.

.
1.
,
Type.
Type
week=(sunday, monday, tuesday, wednesday, thursday,
friday, satufday);
work_week=monday..friday;
day=1..31;
,
, ,
.

,
.
.
,
, .
,
Var month(january, february, march, april, may, june, july, august,
september, october, november, december);

PDF created with pdfFactory Pro trial version www.pdffactory.com

37

.
.
, ,
, ,
, .
,
:
Pred(x) , ;
Ord(x) ;
Succ(x) , .

. , , february<november.
3. :
) Ord(august);
) Ord(succ(september));
) Pred(Pred(december)).
4. :
var x,y : (winter, spring, summer, autumn);
t : (cold, warm);
) :x:=spring; t:=warm: t:=hot; y:=x; y:=t;
) :
spring<summer;
autumn<winter;
Succ(spring);
Pred(autumn);
Ord(spring);
winter<=summer;
spring<>warm;
Pred(spring);
Pred(cold);
Pred(autumn) + Ord(cold);
) : For x:=spring To autumn Do

5. :
VAR m, m1: (january, february, march, april, may, june, july, august,
september, october, november, december);

PDF created with pdfFactory Pro trial version www.pdffactory.com

38
k: 1..maxint; n: 1..12;
m1:
) , m;
) k- n.
6. :
VAR d: 0..9; k: 0..9; n: integer;
) d ?
? : d:=7; d:=a; d:=7 ?
) k ?
? : k:=5; k:=10; k:=-0: k:=5 ?
) :
if k+n>7*k then k:=abs(n) mod 10
else d:=chr(k+Ord(0) ?

13.

,
(). .
, ,

(For, While, Repeat ... Until).
: , ,
10 , - 5 , - (0,5 ),
, 100 100 .
: b- , k -
, t - .
:
10b+5k+0,5t=100 b+k+t=100
:
20b+10k+t=200 b+k+t=100
100 :
10 , .. 0<=b<=10;
20 , .. 0<=k<=20;
200 , .. 0<=t<=200;

PDF created with pdfFactory Pro trial version www.pdffactory.com

39
:
Program skot;
Var b,k,t : integer;
Begin
For b:=0 to 10 do
For k:=0 to 20 do
For t:=0 to 200 do
if (20*b+10*k+t=200) and (b+k+t=100) then
writeln( ,b, ,k, ,t);
end.

11*21*201=46431 .
:
t=100-(b+k)

14.

-
, .
- .
.
30 .
Var mas: array [1..30] of integer;



1) .
[1]:=3;
[2]:=4;
........

B[1]:=;
B[2]:=;
........

PDF created with pdfFactory Pro trial version www.pdffactory.com

40
,
.
2) .
For i:=1 to 10 do
begin
Writeln( ,i,- );
Readln(a[i]);
{ }
end;

.
3)
.
.......
RANDOMIZE;
For i:=1 to 10 do
a[i]:=Random(x);
....
{ 0 }
4) .

( ai=sin i - cos i)
for i:=1 to 10 do
a[i]:=sin(i)-cos(i);

.
For i:=1 to 10 do writeln(a[i]);
: write(a[5]);

PDF created with pdfFactory Pro trial version www.pdffactory.com

41

1) .
Program symma;
var a: array [1..10] of integer;
i, s : integer;
begin
s:=0;
for i:=1 to 10 do
begin
readln(a[i]);
s:=s+a[i];
end;
writeln (= ,s);
nd.
2) .
Program symma2;
var a: array [1..10] of integer;
i, s : integer;
begin
s:=0;
for i:=1 to 10 do
begin
readln(a[i]);
if a[i]>0 then s:=s+a[i];
end;
writeln ( = ,s);
nd.
3) .
Program symma-kol;
var a: array [1..10] of integer;
i, s,k : integer;
begin
s:=0; k:=0;

PDF created with pdfFactory Pro trial version www.pdffactory.com

42
for i:=1 to 10 do
if a[i]>0 then begin k:=k+1; s:=s+a[i]; end;
writeln ( ,s, , k);
nd.
4) .
5.
Program elem;
var a: array [1..10] of integer;
i : integer;
begin
for i:=1 to 10 do
if a[i]>5 then writeln(a[i]);
nd.
5) () .
Program mm;
var a: array [1..10] of integer;
i, max, min : integer;
begin
for i:=1 to 10 do readln(a[i]);
max:=a[1]; min:=a[1];
for i:=1 to 10 do
begin
if a[i]>max Then max:=a[i];
if a[i]<min Then min:=a[i];
end;
writeln ( max=,max, min=, min);
nd.
6)
() -
.
.
.
10 : 5 13 7 9 1 8 16 4 10 2.
: 1 2 4 5 7 8 9 10 13 16

PDF created with pdfFactory Pro trial version www.pdffactory.com

43

, , , .
.
1
5 13 7 9 1 8 16 4 10 2
- 16.
-
2.
2 . 5 13 7 9 1 8 2 4 10 16
,
. - 13,
. -
10.
..
:
for i:=n downto 2 do
begin { }
maxi:=i;
for j:=1 to i-1 do if a[j]>a[maxi] then maxi:=j;
if maxi<>i then begin { }
k:=a[i]; a[i]:=a[maxi]; a[maxi]:=k
end;
end;

.
.
,
.
Program sort1;
const n=10;
label metka;
var a: array [1..n] of integer;
i, c, k : integer;
begin
for i:=1 to n do readln(a[i]);

PDF created with pdfFactory Pro trial version www.pdffactory.com

44
metka: k=0; { }
for i:=1 to n-1 do
if a[i]>a[i+1] then begin c:=a[i];
a[i]:=a[i+1];
a[i+1]:=c;
k:=1;
end;
if k=1 then goto metka
else writeln();
for i:=1 to n do writeln(a[i]);
nd.
,
Program sort2;
const n=10;
var a: array [1..n] of integer;
i, k, c : integer;
begin
for i:=1 to n do readln(a[i]);
for i:=1 to n-1 do
for k:=1 to n-i do
if a[k]>a[k+1] then begin c:=a[k];
a[k]:=a[k+1];
a[k+1]:=c;
end;
for i:=1 to n do writeln(a[i]);
nd.



:
program mass;
const n=30;
type mas=array[1..n] of integer;

PDF created with pdfFactory Pro trial version www.pdffactory.com

45
var a : mas;
i : integer;
begin
for i:=1 to n do { }
begin write( ,i, ); readln(a[i]);
end;
for i:=1 to n do writeln(a[,i,]=,a[i]); { }
for i:=1 to n do
if a[i]<0 then a[i]:=abs(a[i]);
for i:=1 to n do writeln(a[,i,]=,a[i]); { }
end.
, :
) 25;
) , ,
- .
.
) ;
) .

15. .
.
CHAR
STRING
,
, ,

PDF created with pdfFactory Pro trial version www.pdffactory.com

46
. ,
, ..

.
-
.
- ( ) 0
255.
-
, .

var <> : string
[ ];
:
const adres=., 5;
var s:string; d : char;
st1, st2 : string [30]

, readln .

) (<>,<,>, >=,<=,=)
d:=; p:=
d>p
) ()
s:=+;
writeln(s);
: :
var A,B,C,D,G,Z : STRING;
v : integer;

PDF created with pdfFactory Pro trial version www.pdffactory.com

47
begin
A:= ;
B:=;
:=;
D:=25 ;
G=25;
Z:=;
V:=;

)
1. Delete(str,poz,n) - str, poz,
n .
:
str:=;
Delete(str,2,2)

2. Insert(str1,str2,poz) - str1 str2,
poz.
:
str1:=;
str2:=;
Insert(str1,str2,6)

3. Length(st) - ( )
.
:
str:=;
Length(str)
8
4. Copy(st,poz,n) - st, poz, n
;
:
str:=;
Copy(str,2,6)

PDF created with pdfFactory Pro trial version www.pdffactory.com

48

5. Pos(str1,str2) - str2 str1
, str2,
, 0.
:
str1:=; str2:=;
pos(str1,str2)
2
6. Str(v,s) - v s;
7. Val(s,v,c) - s ,
v.
8. Concat(s1,s2,....,sn) - s1,s2,....,sn
.
1 : :

.
s:=;
st:=;
a:=Length(s++st);
n:=Pos(st,s);
insert(st,s,6);
delete(s,4,2);
st:=copy(s,1,3)+copy(s,7,1);
2. ,
0123456789
2 , ,
.
: 7
9
program z2;
const a=;
b=0123456789;

PDF created with pdfFactory Pro trial version www.pdffactory.com

49
var s1,s2 : string;
begin
s1:=copy(a,6,5)++ copy(b,6,1)+ copy(b,14,1)
s2:= copy(a,1,5)++ copy(b,length(b),1)+ copy(b,2,1)
writeln(s1,s2);
end.
0 255.
ORD(w) - w.
CHR(i) - i.
1. .
.
Program xx;
var st:string; i:integer;
begin
for i:=1 to length(st) do
writeln(st[i]);
end.
2. .
k
15 .
Program kod;
var i, k : integer;
begin
writeln( () -
i );
for i:=1 to 255 do
begin
write(i:4, ,chr(i)); inc(k);
if k=15 then begin writeln; k:=0 end
end;
end.
3: :
A

PDF created with pdfFactory Pro trial version www.pdffactory.com

50
BB
CCC
...
WWW...WWW (23 )
program vv;
var i:char; j:integer;
begin
for i:=A to W do
begin
for j:=1 to Ord(i)-Ord(A)+1 do write(i);
writeln;
end;
end.
4.
.
Program rr;
var st:string; k:integer;
begin k:=length(st);
if k mod 2=1 then delete(st, k div 2+1,1)
else delete(st, k div 2,2)
end.

16.


(, ..). ,
.
:
5 4 3 6
2 8 1 7
4 3 9 5
3 4, ..
. ,

PDF created with pdfFactory Pro trial version www.pdffactory.com

51
, [i,j]
i (i=1,2,3),
j - (j=1,2,3,4).
:
1 :
Type T=array [1..3,1..4] of integer;
Var A: T;
2 :
Var A: array [1..3,1..4] of integer;

( ) .
:
for i:=1 to m do { , }
.......
for j:=1 to n do { , }
..........
:
for j:=1 to n do { , }
.......
for i:=1 to m do { , }
.
1. :
) ;
)
2. .
3. .
4. ()
() .
5. .
6. () .
() ()
For i:=1 to n do

PDF created with pdfFactory Pro trial version www.pdffactory.com

52
For j:=1 to m do
Readln(A[i,j]);
1. .
3 4 , .. 34=12
For i:=1 to 3 do
For j:=1 to 4 do
a[i,j]:=random(100);

11
21
.

12
.
.

13
.
.

2. :
For j:=1 to 4 do
11
12
For i:=1 to 3 do
21
.
a[i,j]:=random(100);

.
31

.
.
.

14
.
.

.
.
.

3. :
For i:=1 to n do
begin
For j:=1 to m do
Write (A[i,j]); {
}
Writeln; { }
end;

- ;
i - ;
j - ;
n - ;
m - .
4. , .
NxN, .
.
Program pr2;

PDF created with pdfFactory Pro trial version www.pdffactory.com

53
CONST N=3;
TYPE MAS=array [1..N,1..N] of real;
Var a: MAS;
i: 1..3;
j : 1..3;
s:real;
BEGIN
Writeln( );
For i:=1 to n do
For j:=1 to n do
Readln(a[i,j]);
{ }
For i:=1 to n do
begin
For j:=1 to n do
Write (a[i,j]:5:1);
Writeln;
end;
s:=0; j=1;
For i:=1 to n do
s:=s+a[i,j];
Writeln( = ,s:5:2);
end.
5. .
......
S:=0;
for i:=1 to m do
for j:=0 to n do
S:=S+a[i,j];
.............
6. ()
.
:
For i:=0 to m do
begin

PDF created with pdfFactory Pro trial version www.pdffactory.com

54
max:=a[i,1];
ind_L:=i; { }
ind_C:=1; { 1 - }
for j:=1 to n do
if a[i,j]>max then begin
max:=a[i,j];
ind_C:=j { j- }
end;
writeln(max ,i,=,max)
end;
:
For j:=0 to n do { }
begin
min:=a[1,j];
ind_L:=1; { }
ind_C:=j; { }
for i:=1 to m do
if a[i,j]<min then begin
min:=a[i,j];
ind_L:=i { j- }
end;
writeln(min ,,j, ,min)
end;
7.
.
Min:=a[1,1];
ind_L:=1;
ind_C:=1;
for i:=1 to m do
for j:=1 to n do
if a[i,j]<min then begin
min:=a[i,j]; ind_L:=i; ind_C:=j;
end;
8. .
Type mas4x4=array[1..4,1..4] of integer;
var a: mas4x4;

PDF created with pdfFactory Pro trial version www.pdffactory.com

55
a11

a12

a13

a14

a21

a22

a23

a24

a31

a32

a33

a34

a41

a42

a43

a44

a12

a13

a14

a23

a24
a34

- a11, a22, a33,


a44 ( ,
(i=j)
- a41, a32, a23,
a14 ( 1
( ), ..
i+j=4=1 i+j=n+1.

, - .

,
, ,

i<j;

a21

,
,
,

i>j;

a31

a32

a41

a42

a43

:
1) :
S:=0;
for i:=1 to n do
S:=S+a[i,i];

PDF created with pdfFactory Pro trial version www.pdffactory.com

56
2) :
min:=a[1,n];
for i:=1 to n do
if a[i,n+1-i]<min then min:=a[i,n+1-i];

1. , 3
5 . .
Program pr1;
CONST N=3; M=5;
TYPE MAS=array [1..N,1..M] of real;
Var b: MAS;
i: 1..N;
j : 1..M;
p:real;
BEGIN
Writeln( );
For i:=1 to n do
For j:=1 to m do
Readln(b[i,j]);
{ }
For i:=1 to n do
begin
For j:=1 to m do
Write (b[i,j]); {
}
Writeln; {
}
end;
p:=1;
For i:=1 to n do
For j:=1 to m do
p:=p*b[i,j];
Writeln( = ,p:7:2);
end.

PDF created with pdfFactory Pro trial version www.pdffactory.com

57
2. A[N,M]
B[N,M],
SQR(A[I.J]), I- ;
B[I,J] =
SQR(A[I.J]), I- ;
Program pr3;
CONST N=3; M=5;
TYPE MAS=array [1..N,1..M] of real;
Var a,b : MAS;
i: 1..N;
j : 1..M;
BEGIN
Writeln( );
For i:=1 to N do
For j:=1 to M do
Readln(a[i,j]);
{ }
For i:=1 to N do
begin
For j:=1 to M do
Write (a[i,j]:5:1);
Writeln;
end;
For i:=1 to N do
if i/2= int(i/2) Then For j:=1 to M do
b[i,j]:=sqrt (a[i,j])
Else For j:=1 to M do
b[i,j]:=sqr (a[i,j])
For i:=1 to N do
begin
For j:=1 to M do
Write (b[i,j]:7:2);
Writeln;
end;
end.

PDF created with pdfFactory Pro trial version www.pdffactory.com

58

17.
,

,
.
,
,

.
,

, .

, .

,
.
, ,
.


, .

( )
.
- ,
()
.

PDF created with pdfFactory Pro trial version www.pdffactory.com

59


.

.
.
- ,
.
:
Procedure ( );
(* *)
begin
(* *)
end;
,
.
PROCEDURE,
,
( ).
.
, .
, ,
.
BEGIN END,
END .

, , , , ,
.
:
( );

PDF created with pdfFactory Pro trial version www.pdffactory.com

60

- ,
.
- ,
.

, .
- ,
.

.

.
: -
-.
- ,
Var. , ,

.
- , Var
.
-,
,
,
.
.

.
. ,
.
. n :
n (n>=0) . (
).
Program ex;
var a, n : integer;

PDF created with pdfFactory Pro trial version www.pdffactory.com

61
s: longint;
Procedure Degree(x,y : integer; var st : longint);
var i : integer;
begin
st:=1;
for i:=1 to y do st:=st*x;
end;
{ }
begin
writeln( - );
readln(a,n);
Degree(a,n,s); { }
writeln( ,s);
end.
Degree.
,
. : -
, , ; , - .
- , - -,
var. (x y integer, st - Longint,
).
.
,
i ( ).
.
Begin End,
( End
). x
For.

, ,
Begin , .
!!!! ,
. .

PDF created with pdfFactory Pro trial version www.pdffactory.com

62
x, y st
a, n s .
a n
, , s .
2 : ,
: y=a4x4 + a3x3 + a2x2 + a1x + a0
program ex2;
var a: array[0..4] of integer;
i, x: integer;
y,s: longint;
Procedure Degree(xx,n : integer; var st : longint);
var i : integer;
begin
st:=1;
for i:=1 to n do st:=st*xx;
end;
{ }
begin
write( ); readln(x);
writeln( );
for i:=0 to 4 do begin write(a[,i,]=); readln(a[i]); end;
y:=a[0];
for i:=1 to 4 do
begin
Degree(x,i,s); y:=y+a[i]*s;
end;
writeln(y=,y);
end.
3. .
Program sumir;
var a: array [1..100] of integer; sa1, sa2,sa3 : integer;
n,l,t : integer;
procedure summa(a:array [1..100] of integer; k,m :integer; var
s:integer);
var i:integer;

PDF created with pdfFactory Pro trial version www.pdffactory.com

63
begin
s:=0;
for i:=k to m do s:=s+a[i];
end;
BEGIN
for t:=1 to 100 do
begin
write( );
readln(a[i]);
end;
summa(a,10,20,sa1);
summa(a, n , l , sa2);
summa(a, n,n+3,sa3);
end.

Function,
,
,
.

,
, - .
.
, :
Function [( )]:

Begin
,
_:=
End;

PDF created with pdfFactory Pro trial version www.pdffactory.com

64
1 ,
n k.
n!
k =
n k!( n k )!
n k ;
- .
n.
(n!=1*2*..*n)
program sochet;
var n,k : integer;
a1,a2,a3,c : lohgint;
Function factorial(n:integer):longint;
var i: integer;
rez : longint;
begin
rez:=1;
for i:=1 to n do rez:=rez*i;
factorial:=rez;
end;
begin
writeln( n k :); readln(n,k);
a1:=factorial(n); { n!}
a2:=factorial(k); { k!}
a3:=factorial(n-k); { (n-k)!}
c:=a1 div (a2*a3); { }
writeln(=,c) ;
end.
- .
Function () , factorial
.
, .
.
factorial - .
,
, ,

PDF created with pdfFactory Pro trial version www.pdffactory.com

65
, , . i
( ) rez ( ).
( ).

,
.
n=5,
k=3.
a1:=factorial(n), :
, factorial;
:
n:=n (n=5);
, 5;
,
a1;
a2:=factorial(k)
a3:=factorial(n-k)

factorial k=3 n-k=2.
- ,
,
. ,
,
, ( n
n ).
, ..
.
2 : ,
. , ,
.
Program chisla;
Var n1, n2 : longint;
k1, k2 : byte;
Function kol(x : longint): byte;
var k: byte;
begin
k:=0;
While x<>0 do
begin

PDF created with pdfFactory Pro trial version www.pdffactory.com

66
Inc(k);
x:=x div 10;
end;
kol:=k;
end;
BEGIN
writeln( ); readln(n1, n2);
k1:=kol(n1);
k2:=kol(n2);
if k1=k2 Then writeln( )
else if k1>k2 Then Writeln( )
else writeln( )
END.

18.

, ,
.
,
, - .
4 .
I.
,

.
: .
N! =

1 N=1
N(N-1)! N>1

Function factorial(n:integer): longint;


begin
if n=1 Then factorial:=1
else factorial:=n*factorial(n-1);

PDF created with pdfFactory Pro trial version www.pdffactory.com

67
end;
5 . N=1 - .
2.
n m,
.
m+1, n=0
A(n,m) =
A(n-1,1), n0, m=0
A(n-1,A(n,m-1)), n>0, m0
3. N .
, , ,
1 (1, 1, 2, 3, 5, 8, 13, 21...)
(n)=
=

1, n=1 n=2
(n-1) + (n-2), n>2

4. N
() .

II. ,


, .
1. .
a b, 1. :
b=0, a+b=a
b>0, a+b=(a+1)+(b-1)
b<0, a+b=(a-1)+(b-1)
.
Function Sum(a, b : integer) : integer;
begin
if b=0 Then Sum:=a
else if b>0 Then Sum:=Sum(a+1, b-1)
else Sum:=Sum(a-1, b+1);
end;

PDF created with pdfFactory Pro trial version www.pdffactory.com

68
2. .(2 )
a b.
a=b, (a,b)=a.
a>b, (a,b)=(a-b,b).
a<b, (a,b)=(a,b-a).
Function NOD(a,b : integer) : integer;
begin
if a=b Then NOD:=a
else if a>b Then NOD:=NOD(a-b,b)
else NOD:=NOD(a,b-a) ;
end;
a
123
87
51
15
15
15
9
3
3

b
36
36
36
36
21
6
6
6
3

a>b, a:=a-b
a:=a-b
a:=a-b
b>a, b:=b-a
b:=b-a
a:=a-b
a:=a-b
b:=b-a
a=b, :=a

3.
.
Function Rec(n: integer);
begin
if n>1 Then Rec(n div 2);
Write(n Mod 2);
end;

III. ,

PDF created with pdfFactory Pro trial version www.pdffactory.com

69
,
, (,
). .

.
1 ,
.
, , : ,
, N ,
(2MN), N.

:
M=N;
N
+1 N.
Function Simple(m,n : integer): boolean;
begin
if m=n Then Simple:=True
else Simple:=(n Mod m <> 0) And Simple(m+1,n);
end;

IV. ,

1. N1
a, :
2-1 N < 2a.
a(N) = 1 , N=1
a(N)=a(N div 2) + 1, N>1
. N=34.
2a-134<2a, 1 34 div 2
2a-117<2a +1
2a-1 8<2a +1
2a-1 4<2a +1
2a-1 2<2a +1
2a-1 1<2a ; =1

PDF created with pdfFactory Pro trial version www.pdffactory.com

70
,
. , 6.
Function A(N : integer) : integer;
begin
if N=1 then a:=1 else a:=a (N div 2) +1;
end;

19.


(),
.

.
640480 - 640 , 480.
: X, Y .

(0,0)
(640,0)

(0,480)

(640,480)


GRAPH,
.
.BGI
,
GRAPH, ,
:
USES GRAPH;
GRAPH
.

PDF created with pdfFactory Pro trial version www.pdffactory.com

71
InitGraph,
.
:
InitGraph( Driver, Mode,c:\tp7\bgi);
Driver Mode :
var Driver, Mode : integer;
,
, :
Driver:=Detect; InitGraph(Driver, Mode,c:\tp7\bgi);

CloseGraph.

SetColor(< >:word); -
.
SetBkColor(<
;

>:word);

SetFillStyle(< >:word; <


>:word); - .

Black
Blue
Green
Cyan
Red
Magenta
Brown
LightGray
DarkGray
LightBlue

0
1
2
3
4
5
6
7
8
9

-
-
-

PDF created with pdfFactory Pro trial version www.pdffactory.com

72
LightGreen
LightCyan
LightRed
LightMagenta
Yellow
White

10
11
12
13
14
15

-
-
-
-

EmptyFill
0
SolidFill
1
LineFill
2
LtslashFill
3
SlashFill

BkslashFill

LtbkSlashFill

HatchFill

XhatchFill

InterLeaveFil

WideDotFill
CloseDotFill

10
11




-- //
.
//
.
\\
.
\\
.







PDF created with pdfFactory Pro trial version www.pdffactory.com

73

1. .

. ,
( ).
, .

MoveTo(x,y) -
(x,y).
MoveRel(dx, dy) - dx

dy .

1. ...........
MoveTo(200,100);
MoveRel(5,10); { (205,110)}
...........
X Y
,
GetMaxX : integer;
GetMaxy : integer; Y
.

.........
var Xcentr, Ycentr : integer;
..........
begin
...........
Xcentr:=GetMaxX div 2;
Ycentr:=GetMaxy div 2;
MoveTo(Xcentr, Ycentr);
.............
2.
PutPixel(x,y : integer; < >);
x,y .

PDF created with pdfFactory Pro trial version www.pdffactory.com

74
3.
Line(x1,y1,x2,y2);
(x1,y1) -
(x2,y2) -
!!! , .
SetColor().
LineTo(x,y) -
(x,y).
LineRel(dx,dy) -
(x+dx, y+dy)
4.
Rectangle(x1,y1,x2,y2:integer);
Bar(x1,y1,x2,y2:integer) -
, SetFillStyle().
5. , , .
Circle(x,y,<> : word); -
Ellipse(x,y:integer; <_>,<_> :word; xR,yR : word) .
X,Y - ,
xR, yR -
.

.
. 0, 360 .
6. :
FillEllipse(x,y:integer; xR,yR);
X,Y - ,

PDF created with pdfFactory Pro trial version www.pdffactory.com

75
xR, yR -
.

SetFillStyle(), - SetColor().
7.
.
FloodFill(x,y:integer; < >);
SetFillStyle()
X,Y - ( ) .
. ,
\\ - . .
Program graph1;
uses Graph;
var Driver, Mode : integer;
begin
Driver:=Detect;
{ }
InitGraph(Driver, Mode,)
{ }
SetBkColor(15);
{ - }
SetColor(1);
{ - }
Cleardevice;
{ }
SetFillStyle(5,8);
{ }
Rectangle(290,290, GetMaxX-290, GetMaxy-290); {}
FloodFill(301,230,1);
{

}
ReadLn;
CloseGraph;
end.
2. y=sinx y -100,100
y=100*sinx, 0<x<2pi, Dx=pi/100.
Program sinus;
uses crt, graph;
var gt, gr : integer;
xm,ym,i : integer;

PDF created with pdfFactory Pro trial version www.pdffactory.com

76
dx,x1,y1,x2,y2:real;
begin
gt:=detect; initgraph(gt,gr,);
xm:=getmaxx div 2;
ym:=getmaxy div 2;
setcolor(3);
line(0,ym-100,0,yn+100); line(0,ym.getmaxx,ym);
{
}
outtextxy(100,ym+50,pi); { }
moveto(0,ym);
dx:=oi/100;
x1:=0;
setcolor(5);
while x1<=200 do begin
y1:=100*sin(x1*dx);
x2:=x1+dx;
y2:=100*sin(x2*dx);
line(round(x1),ym+round(y1),round(x2), ym+round(y2));
x1:=x2;
y1:=y2
end;
readln;
closegraph;
end.

PDF created with pdfFactory Pro trial version www.pdffactory.com

77


.
20.

, , ,
. ,
. ,
. ?
,
, .
- ,
.
.
. ,
,
.

:
var < >: File of < >;
:
var Ft : File of integer;
M : File of char;
Type File_integer=File of integer
File_char=File of char;
Var F1: File_integer;
F2: File_char;
,
. .
.
,
.
(0)
(1)
...
()
(+1)
...

PDF created with pdfFactory Pro trial version www.pdffactory.com

78

.

Assign(< ->,< >);


:
Assign(F1,A:INT.DAT);
,
F1, ,
INT.DAT

: , .

.
,
, .

Reset(< >);

Read(< >,< >);
, . ,
Read(< >),
, Read(< >,<
>); , .


,

Close(< >)
, , :
Reset(< >);

PDF created with pdfFactory Pro trial version www.pdffactory.com

79
.......
Read(< >,< >);
...........
Close(< >);


,
, .
Eof(< >) (Eof - End Of File).
(rue), , (False) -
.
:
Assign(F1,A:INT.DAT);
Reset(F1);
While Not Eof(F1) do
begin
read(f1,n); { }
write(n, ); { }
end;
Close(F1);

Rewrite(< >);
:

Write(< >,<>);
, , :
Rewrite(<>);
......
Write(< >,<>);
..........

PDF created with pdfFactory Pro trial version www.pdffactory.com

80
Close(< >);


,
,
. ,
.
.
Seek(< >,N)
N- . , Seek(F1,3). ( 4 )

FilePos(< >)
, .

FileSize(< >)
.

Erase(< >) .
Rename(< >,< >)
.
: DAT1.DAT .

DAN2.DAT
Program WW;
Var f1,f2 : file of integer;
s, n : integer;
begin
Assign(f1,DAT1.DAT);
Reset(F1);
Assign(f2,DAT2.DAT);
Rewrite(f2);
s:=0;
While Not Eof(f1) do { }
begin

PDF created with pdfFactory Pro trial version www.pdffactory.com

81
read(f1,n); { F1}
write(f2,n); { F2}
s:=s+n;
end;
write(f2,s); { F2}
write( DAT2.DAT);
Close(f1);
Close(f2);
end.

21.
.
, .
Text:
Var A: Text;

, .

Assign.
Reset Rewrite.
Read.
,
Readln. ,
Readln(<
>);
.
Write .
,
Writeln.
, Writeln(<
>);
.
,
Eoln(< >),
True, .
Append(< >).
, .

PDF created with pdfFactory Pro trial version www.pdffactory.com

82
: , ,
,
.
.
: :
-32 16 0 8 7
4 5 9 13 11 -5 -8
6 -8 0 -12
5 4 3 2 1 12
1 2
:
New File;
, , ,
;
, , INT1.DAT

program rrr;
var f : text;
x, k: integer;
begin
Assign(f,int1.dat);
Reset(f);
While Not Eof(f) do { }
begin
k:=0;
While Not Eoln(f) do { }
begin
read(f,x); { }
write(x, ); { }
Inc(k); { }
end;
writeln( , k, );
Readln(f) { }
end;
Close(f);
end.
. 54
.

PDF created with pdfFactory Pro trial version www.pdffactory.com

83
Program mas;
const m=5; n=4;
Var fil : text;
a: real;
s: char;
i,j : integer;
begin
Assign(fil,massiv.txt);
Rewrite(fil);
for i:=1 to m do
begin
for j:=1 to n do
begin
a:=random(100);
write(fil,a:5:3, ); { ,
}
end;
writeln(fil); { }
end;
Close(fil);
{ }
Reset(fil); { }
while not Eof(fil) do
begin
while not Eoln(fil) do
begin
read(fil,a); { }
write(a:5:3);
read(fil,s); { }
write(s);
end;
writeln;
readln(fil);
end;
Close(fil);
end.
. f. g
f .
program tofile;
var f, g : text;

PDF created with pdfFactory Pro trial version www.pdffactory.com

84
n, i, j : integer;
s : string;
x : array [1..32000] of char;
begin
assign(f,f.txt); assign(g,g.txt);
rewrite(g); rewrite(f);
writeln( );
readln(n);
writeln( , Enter);
for i:=1 to n do begin readln(s); write(f,s); end;
reset(f);
i:=0;
writeln( :);
while(not eof(f)) and (i<32000) do
begin i:=i+1; read(f,x[i]); write(x[i]); end;
writeln;
writeln( :);
for j:=i downto 1 do
begin write(g,x[j]); write(x[j]); end;
writeln;
close(f); close(g);
end.
. .
.
. .
, , .

22.

() .
- .
256 .

- (
)

PDF created with pdfFactory Pro trial version www.pdffactory.com

85
, ,
Type:
Type < > = Set Of < >;
Var < > : < >;
Var:

Var

< > : Set Of < >;

.
Type mnog_Char=Set Of Char;
Var mn1 : Set Of Char;
mn2 : mnog_Char;
mn3 : Set Of A..Z;
s1 : Set Of Byte;
s2 : Set Of 1000..1200;
mn1 mn2 - ;
256, Char ;
mn3 - ;
s1 - ( 0 255); Byte
0 255,
;
s2 - 1000 1200.
() .
, .
, .
Type digit = Set Of 1..5;
Var s : digit;
s ,
1 5;
[ ] - ;
[1], [2], [3], [4], [5] - ;
[1,2], [1,3], ...., [2,4], [4,5] - (
);
[1,2,3], [1,2,4], ... , [3,4,5] - ( );
[1,2,3,4], [1,2,3,5], [1,2,4,5], [1,3,4,5], [2,3,4,5] - ;
[1,2,3,4,5] - ( ).

PDF created with pdfFactory Pro trial version www.pdffactory.com

86
,
.
- +.

A+B

1) [A, F] + [B, D] = [A, F, B, D];


2) [1..3, 5, 7, 11] + [3..8, 10, 12, 15..20] = [1..8, 10..12, 15..20]
S1:=[1..5, 9], a S2:=[3..7, 12]. S:=S1 + S2,
S=[1..7, 9, 12].
1:=[a..z]; A1:=A1 = [A]. A1=[A, a..z].

,
, .
- *.

A*B

.
1) [A, F] * [B, D] = [ ] , ;
2) [1..3, 5, 7, 11] * [3..8, 10, 12, 15..20] = [3, 5, 7];
3) S1:=[1..5, 9] S2:=[3..7, 12], a S:=S1 * S2, S=[3..5].
,
, .
-

A-B

.
[A, F] - [B, D] = [A, F ] , ;
[1..3, 5, 7, 11] - [3..8, 10, 12, 15..20] = [1, 2, 11];
S1:=[1..5, 9] S2:=[3..7, 12], a S:=S1 - S2, S=[1, 2, 9];
A1:=[A..Z]; A1:=A1 - [A]. 1=[B..Z].

PDF created with pdfFactory Pro trial version www.pdffactory.com

87



in.
true, , false
.
.
1. 5 in [3..7] true, 5 [3;7]
2. a in [A..Z] false,
.


:
= - () ;
<> - ;
<=, < - ;
>=, > - .

(AB)

A
true

false

true

(A<B)
B
B
true

A
false

A
false

.
1 30 :
- , 2;

PDF created with pdfFactory Pro trial version www.pdffactory.com

88
- , 3;
- , 6;
- , 2 3;
:
1. ? ( ? (
Byte).
2. ? ( ).
3. ? (
,

).
4. ? (
,
, .

).
Program mnog;
const n=30;
type mn=Set Of 1..n;
var n2, n3, n6, n23 : mn;
k : integer;
procedure print(m: mn);
var i: integer;
begin
for i:=1 to n do if i In m then write(i:3);
writeln;
end;
BEGIN
n2=[ ]; n3=[ ];
for k:=1 to n do
begin
{ 2, n2 }
if k Mod 2 = 0 Then n2:=n2+[k];
{ 3, n3 }
if k Mod 3 = 0 Then n3:=n3+[k];
end;
{, 6, - , 2 3,
, , 2 3, -
}

PDF created with pdfFactory Pro trial version www.pdffactory.com

89
n6:=n2*n3; n23:=n2+n3;
writeln(, 2); print(n2);
writeln(, 3); print(n3);
writeln(, 6); print(n6);
writeln(, 2 3); print(n23);
END.
2. , ,
, . ?
program bob;
var y1, y2, y3, y4, x : Set Of Char;
s : Char;
BEGIN
y1:=[, , ]; y2:=[, , , , ];
y3:=[, , ]; y4:=[, , , , ];
x:=(y1*y2) + y3 - y4;
writeln( );
for s:=a to do if s In x then write(s); writeln;
{: }
if y3<=x then write( )
else write( );
END.
3.
+ =
,
. ,
.
.
S1 ,
, .
S1 - .
,
. ( S2),
( S1 S2 )
, . S1
.
,
, .
, 1
4, 0.

PDF created with pdfFactory Pro trial version www.pdffactory.com

90
Program myxa;
type mn=Set Of 0..9;
var m, y, x, a : 0..9; { }
n1, n2 : integer; { }
a1, a2, a3, a4 : 0..9; { }
S1, S2 :mn;
procedure Print(x,y:integer); { }
begin
writeln(x:5);
writeln(+);
writeln(x:5);
writeln(____);
writeln(y:5);
end;
BEGIN
s1:=[ ]; s2:= [ ];
for m:=1 to 4 do
begin
s1:=s1+[m]; { }
for y:=0 to 9 do { ,
}
if Not (y In s1)
then begin s1:=s1+[y];
for x:=0 to 9 do
if Not (x In s1)
then begin s1:=s1+x;
for a:=1 to 9 do
if Not (a In s1)
then begin s1:=s1+[a];
n1:=1000*m+100*y+10*x+a;
n2:=2*n1;
a1:=n2 div 1000;
a2:=n2 div 100 mod 10;
a3:=n2 div 10 mod 10;
a4:=n2 mod 10;
s2:=[a1,a2,a3,a4];
if (s1*s2=[]) and ([a1]*[a2]*[a3]*a[4]=[])
then Print(n1,n2);
s1:=s1-[a];
end;
s1:=s1-[x];

PDF created with pdfFactory Pro trial version www.pdffactory.com

91
end;
s1:=s1-[y];
end;
s1:=s1-[m];
end;
END.

23.
()
,
.

.
( )
.
,
.
,
- ,
. ,
, .
- ,
. .
( ) . ,
, , ,
.
:
Type < > = Record
< 1> : < 1>;
< 2> : < 2>
< n> : < n>
End;
:
Type
pupil = Record
fam : string[15];
{ }
b1,b2,b3,b4,b5 : 2..5; { }
sb : Real
{ }

PDF created with pdfFactory Pro trial version www.pdffactory.com

92
End;
25 ,
klass - .
Var klass : array[1..25] Of pupil;
:
1. . , klass[2].fam,
klass[3].sb, klass[1].b4
, .. klass,
:
for i:=1 to 25 do
begin
readln(klass[i].fam);
readln(klass[i].b1);
readln(klass[i].b2);
readln(klass[i].b3);
readln(klass[i].b4);
readln(klass[i].b5);
end;
2. .

, .
:
With < > Do <>;

.

for i:=1 to 25 do
With klass[i] do
begin
readln(fam);
readln(b1,b2,b3,b4,b5);
end;

:
program zap;
Type pupil = Record
fam : string[15];
{ }

PDF created with pdfFactory Pro trial version www.pdffactory.com

93
b1,b2,b3,b4,b5 : 2..5; { }
sb : Real
{ }
End;
Var klass : array[1..25] Of pupil;
p: pupl;
i,m : integer;
sbmax : real;
begin
for i:=1 to 25 do
with klass[i] do
begin
writeln( );
readln(fam);
readln(b1,b2,b3,b4,b5);
end;
for i:=1 to m do { }
with klass[i] do sb:=(b1+b2+b3+b4+b5)/5;
sbmax:=0;
{ }
for i:=1 to m do
if klass[i].sb>=sbmax then sbmax:=klass[i].sb;
for i:=1 to m do { }
if klass[i].sb=sbmax
then with klass[i] do writeln(fam:20, - , sb:6:3);
end.
. .
,
, (
, ),
, , - .
- - :
1 2 1997
:
Type year=1500..2000;
month=1..12;
day=1..31;
data = Record
y : year;
m : month;
d : day;

PDF created with pdfFactory Pro trial version www.pdffactory.com

94
end;
, :
,
, 1;
, :
) , , 1,
1;
) - , 1,
1.
Program datanext;
Type year=1500..2000;
month=1..12;
day=1..31;
data = Record
y : year;
m : month;
d : day;
end;
Var dat, next : data;
Function leap(yy:year):boolean; {
}
begin
leap:=(yy Mod 4=0) And (yy Mod 400 <>0);
end;
Function Dmonth(mm:month; yy : year) : day; {
}
begin
case mm of
1,3,5,7,8,10,12: Dmonth:=31;
4,6,9,11 : Dmonth:=30;
2 : if leap(yy) then Dmonth:=29 else Dmonth:=28;
end;
end;
procedure Tomorrow(td : data; var nd : data); {- }
begin { }
if td.d<> Dmonth(td.m, td.y) then
with nd do
begin
d:=td.d+1;
m:=td.m;
y:=td.y;

PDF created with pdfFactory Pro trial version www.pdffactory.com

95
end;
else { }
if td.m=12 then { }
with nd do
begin
d:=1;
m:=1;
y:=td.y+1;
end;
else { }
with nd do
begin
d:=1;
m:=td.m+1;
y:=td.y;
end;
end;
BEGIN
writeln( , );
readln(dat.d, dat.m, dat.y);
Tomorrow(dat,next);
writeln( );
writeln(next.d, ., next.m, ., next.y);
END.

24. .
1.
1 + x/1! + x2/2! + x3/3! + ...
, ,
, ,
.
:
1) ( );
2) ,
, , .
Program p;
var a: real;

PDF created with pdfFactory Pro trial version www.pdffactory.com

96
x : real;
: real;
i : integer;
S : integer;
begin
readln(x, );
i:=1;
a:=1;
S:=0;
WHILE a> DO
begin
S:=S+a; i:=i+1; a:=a*x/i;
end;
writeln( =,S:4:2)
end.
2.
f(x)=0, f(x) - . *, f(x*)=0.
[a;b], f(a)<0, f(b)>0.
. =(+b)/2 - .
f(c)>0, b , f()<0, .
,
.

f(x)=x2-2,
..

2.
program popolam;
f(x)
const eps=1.0E-3;
var a,b,c:real;
Function eg(x,y:real):boolean;
begin
Eg:=Abs(x-y)<eps
0
a
c
b X
end;
Function F(x:real):real;
begin
F:=Sgr(x)-2
end;
BEGIN
Writeln( ); readln(a,b);

PDF created with pdfFactory Pro trial version www.pdffactory.com

97
if F(a)*F(b)>0 then writeln(
)
else begin
while Not Eg(a,b) do
begin c:=(a+b)/2;
if F(c)>0 then b:=c else a:=c
end;
writeln( ,a)
end;
readln
end.
:
x2-6x+5=0 x-cosx=0 x-lnx-2=0 2x3-9x2-60x+1=0
3. [a,b] (a<b)
. , f(x),
= =b. [a,b] n
x=(bY
a)/n a=x0<x1<...<xi<xi+1<....<xn=b
[xi,xi+1]

f(xi ).

0
a x1 x2........ xn-2 xn
X

:
S=(b-a)/n*(f(x0)+....f(xn-1))
,
,
.
f(x2) [1,2].
2,333....
program trapez;
const eps=1.0E-3;
var a,b,s,dx :real;
i,n : integer;
Function eg(x,y:real):boolean;
begin

PDF created with pdfFactory Pro trial version www.pdffactory.com

98
Eg:=Abs(x-y)<eps
end;
Function F(x:real):real;
begin
F:=Sgr(x)
end;
BEGIN
Writeln( ); readln(a,b,n);
x:=a; dx:=(b-a)/n; s:=0;
For i:=1 to n-1 do
begin
s:=s+F(x);
x:=x+dx;
end;
writeln( = ,(b-a)/n*s);
readln;
end.
:
f(x)=1/(1+x) [0,1]
f(x)=1/x [1,3]
f(x)=sinx [0,/2]
4.

. ,
:
ex=1 + x + x2/2! + x3/3! + ... + xn/n! + ...
sinx=x - x3/3! + x5/5! - x7/7! +...+ (-1)nx2n-1/(2n+1)! +....
cosx= 1 - x2/2! + x4/4! - x6/6! +...+ (-1)nx2n/(2n)! +....
ln(1+x)=x - x2/2 + x3/3 - x4/4 + ...+ (-1)n+1xn/n + ..... (-1<x<=1)
,
, , .
n .
.
,

.
.
sinx.
Program rad;

PDF created with pdfFactory Pro trial version www.pdffactory.com

99
const eps=1.0E-3;
var x,sn,ss : real;
p, n : integer;
{p - }
Function Eg(x,y;real):boolean;
begin
Eg:=Abs(x-y)<eps
end;
Function F(n:integer;var x:real):real;
var i:integer;
s:longint;
begin
s:=1;
for i:=2 to n do s:=s*i;
x:=x*sqr(x); F:=x/s
end;
BEGIN
writeln( );
readln(x);
ss:=0; sn:=x; n:=1; p:=1;
Repeat
ss:=sn; { }
{ }
n:=n+2; p:=-1*p; sn:=ss+p*F(n,x)
Until Eq(ss,sn) or (n>=12);
Writeln(=,sn); readln
end.
5. -
.
- ,
.
,
.
Random(x)
,
[0,a]
Program ss;
var n: integer; { }
a : integer; { }
m, i : integer;

PDF created with pdfFactory Pro trial version www.pdffactory.com

100
x,y : real;
begin
writeln( - );
readln(n,a);
m:=0;
for i:=1 to n do
begin
x:=Rondom(a); y:=Random(a);
if (x,y) then m:=m+1
end;
S:=(m/n)*a*a
writeln( ,s);
end.

PDF created with pdfFactory Pro trial version www.pdffactory.com

101

25.

1.
if then else ;
if then else ;

2. :
if then if then else
else if then else s

3.

if then begin ; ; end


else begin ; ; end;

4.
if then begin if then end
else if then
begin - end ,

PDF created with pdfFactory Pro trial version www.pdffactory.com

102
.
begin end

if then if then
else if then

5.
.
If then for do
else while do begin

end
6.
for do
begin

end;
while do
begin

end;

7. .
For do
begin

end;

PDF created with pdfFactory Pro trial version www.pdffactory.com

103
8.

for do
if then else

9.
for do
for do
begin

end

10.
if
then begin; for do if then begin end
else while s do begin if i then l; m
else k;
end;

PDF created with pdfFactory Pro trial version www.pdffactory.com

104

1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17

18
19
20
21
22
23
24
25


. . .
. -.
. .



.
While
Repeat
.






.

()

2
4
6
10
14
19
23
25
29
32
34
36
38
39
46
51
58
59
64
67
71
78
82
85
92
96
102

PDF created with pdfFactory Pro trial version www.pdffactory.com

Оценить