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

PASCAL

II

2007

681.3.06
32. 923
21

2007 .

.., .

.., . . .. , .
.., .

- , . , .
,
, .

.. PASCAl. II. . .-. . .


, , 2007


1. : Turbo Pascal ............................... 5
2. : ........................................................................................ 9
3. : , ................ 13
4. : ............................................................................. 18
5. : ............................................................ 24
6. : For ............................................................................................... 29
7. : While ........................................................................................... 35
8. : Repeat... Until.............................................................................. 39
9. : ...................................................................................... 44
10. : . ......................................... 50
11. : ................................................................................................. 59
11. : ..................................................................................................... 69
12. : ..................................................................................................... 77
14. : ............................................. 87
15. : ...................................................................... 94
16. : . .......................................... 101
17. : . ............................................ 104
18. : ................................................................. 110
19. : .................................................................................... 113
20. : () ............................................. 120
21. : ........................................................................ 128
............................................................................................................... 131

.
1. : Turbo Pascal
:
1. (. : . 71 - 74);
2. ;
3. - :
( . :
. 49 - 68);
;
;
.

. .
Program prl_l ;
Var a, b, rez : Integer;
Begin
WriteLn (' '); ReadLn (a, b);
rez :=a*b; WriteLn (' ', rez);
WriteLn (' <Enter>'); ReadLn
End.
, :
Program < >;
,
(, , , , , ),
.
,
Begin End. , . , , . End .
pr1_1 (,
, , , "_").
- . Var,
, . () ,
.
: (a, b rez) (integer),
.
- . (, ) , . 5

.
(.. ,
) .
,
Begin, . - WriteLn ('
') - () , , Ln Write ,
.
- ReadLn (, b) - . .
, , b , . , 12
45, = 12, b = 45. Ln .
: rez :=a*b; (:= -
).

. .
rez ,
a b (.
).
, rez Integer (
).

- WriteLn (' , rez), , ,


- rez. - WriteLn : " <Enter>", ReadLn . End, .
.
. , ( <F10>), Run <Enter>.
: . .
< Enter>, :

<Enter>
rez, , ). , <Enter>.
. , :
6

File;
<Enter>, Save as
<Enter>;
(, prim1_1.pas)
<Enter>.

() STUDENT, , (, 622):
C:\STUDENT\622\PRIM1_1.PAS. C:\ , , PRIM1_1 ( 8 ), PAS - , ,
, .
:
1. : *, =, +, [, ], \, |,
:, ., <, >, /, ?, .
2. Save <F2> Save
all File.

. , :
1. File;
2. <Enter> Quit,
<Enter>, <Alt> + <>.


1. , ,
4567 789. , (-1117). b, .
2. - . , "Error 106: Invalid numeric format" (. , . 66).
3. WriteLn. , , "Error 8:
String constant exceeds line".
4. rez:=a*b rez:=a-(a Div b)*b. Div . WriteLn, .
5. ost,
ost:=a Mod b; WriteLn ('???????? ', ost). ,
Mod. .
6. :
Program pr1_2;
Var a : Integer;
Begin

.
WriteLn (' '); ReadLn () ;
WriteLn ( ' ???????? ', Abs (a)); WriteLn (' <Enter> ' );
ReadLn;
End.
, Abs.
sqr (a), Ord (a) , Succ (a) , pred (a).

1. , .
2. , .
3. : ( + (d - 12) *3) * ( - 5*k),
, d, k .
4. ( , ), : :=13; :=25; t:=x; :=; y:=t;
5. , : := ; :=+; :=-;
6.
13
100
1000
14
101
1001
15

102

1003
16
103
1004


1.

. 1968 -1970 . (,
, - 2). 1983 . - , .
- , . . , - ,
. - 1983 , 1984 , . 1985 ,
. (1988 ) ( , ). ,
. 1989 5.5, - .
, ,
- , . 1992 Borland International - Borland Pascal 7.0 Turbo
Pascal 7.0. Turbo Pascal 7.0 . ,
. , , , , , .
8

.
2. - , . . ,
,
. ,
, ,
. ()
, . , .
3. :
-. "" ,
, - - , -
- .
. ( ) ( ).

2. :
:
1. (. 1, .
20 - 27).
2. .
3. :
;
;
.
4. .

. : ShortInt, Integer, Longlnt, Byte, Word. , , , .


: (+), (-), (*), (Div), (Mod). ,
Ord, Succ Pred.
: "/" .
, . .
. Div Mod
( ) :
19 div 4 = 4;
19 mod 4 = 3
-19 div 4 = - 4;
-19 mod 4 = - 3;
19 div (-4) = - 4;
19 mod (-4) = 3;
-19 div (-4) = 4
-19 mod (-4) = - 3
.
,
.
9

.
Program pr2_1;
Var ,one,dec,hun,rez: Integer;
Begin
WriteLn ( ' ' ) ; ReadLn (a) ;
one :=a Mod 10; WriteLn ( ' - ' , one) ;
dec := (a Div 10) Mod 10; WriteLn ( ' - ', dec) ;
hun := a Div 100; WriteLn ( ' -' ,hun );
rez := hun*100+dec*10+one; WriteLn( a, ' ',rez) ;
Write ( ' <Enter> ' ); ReadLn
End.
137 (one 7, dec - 3
hun 1).
. PRIM2_1. PAS.

1. pr2_1 .
PRIM2_2.PAS.
2. pr2_1 . PRIM2_2.PAS.
3. 10 . ( ) 2, , 137 ( 0, 1).
, . ,
, , 115.
Program pr2_2;
Var rez : Integer;
Begin
WriteLn ( '137 ' ) ; WriteLn ( '10001001' );
Rez := l*128+0*64+0*32+0*l6+1*8+0*4+0*2+1*1;
WriteLn (rez) ;
End.
4. :
Program pr2_3; Uses Crt;
Var a : Integer; b : Word; r1 : Integer; r2 : LongInt;
Begin
ClrScr;{ , Crt}
a:= 32000; b:= 64000; r1 := a+b; WriteLn (r1); r2 := a+b; WriteLn (r2);
End.
, r1 30 464, 2 - 96 000. r1 Word, . ,
. , .
10

.
5. pr2_3 ReadLn :
WriteLn (LongInt (100*a) );
WriteLn (100*LongInt (a) );
LongInt Integer LongInt. , - . , , - 11 264, - , 3 200 000.
, :
1. . , . , Integer
Byte Integer, Integer Word - LongInt. .
2.
!
3. 1
2 ,
Integer, Word.


1. a b
( ):
:= 15 Div (16 Mod 7); b:= 34 Mod a * 5 - 29 Mod 5*2; a:= 4 * 5 Div 3 Mod 2;
b:= 4 * 5 Div ( 3 Mod 2 ).
2. . :
;
, .
3. . :
;
, ;
, ;
, ;
,
(, 137 7137).
.
?
4. 3 ( ) ( ).
5. = 1 + d ( - 1), d
- , - . 1 d. ( ) , Integer.
6. n Sn= (a1 +
an) n / 2. 1 d. ( ) n, Sn Integer.


1. . -
, () - .
(
11

.
), - (
). ,
(. 1, . 33 - 40).
2. - . ,
, , .
, 3377 = 3 1000 + 3 100 + 7 10 + 7 = 3 103 + 3
2
10 + 7 101 + 7 100 3, 7 .
102002:
3377 = 1 55 + 0 54 + 2 53 + 0 52 + 0 52 + 2 50 , (55= 3125, 53 = 125).
110100110001:
3377 = 1 211 + 1 210 + 0 29 + 1 28 + 0 27 + 0 26 + 1 25 + 1 24 + 0 23 + 0 22+ 0 21 + 1
20, (211 = 2048, 210= 1024, 29= 512, 28 = 256, - ..)
:
2
, , 0 1 , ;
, 0. , , .
:
3377 : 2 = 1688 (1) 1688 : 2 = 844 (0) 844 : 2 = 422 (0) 422 : 2 = 211 (0) 211 : 2 = 105 (1)
105 : 2 = 52 (1) 52 : 2 = 26 (0) 26 : 2 = 13(0) 13 : 2 = 6 (1) 6 : 2 = 3 (0) 3 : 2 = 1 (1) 1 : 2 = 0 (1)
. , 337710= 1101001100012.
3. , . , : , , , ,
. , 0 1 , () . , 8
1 , 1024 - 1 (1 ), 1024 - 1 (1 ),
1024 - 1 (1 ). 2 4 0 1: 00, 01, 10, 11 (22). 3 8: 000, 001, 010, 011, 100, 101, 11, 111 (23).
8 , 0 7. 4 , 16
, 0 15. .
, ? - 4
.
. , , , - 5 1101, 5 - 0101. -7 7, .. 15 , 4 16 .
1000 , , , (-0),
.
: 1 .

0001

1110

1111

-1

0010

1101

1110

-2

0011

1100

1101

-3

0100

1011

1100

-4

0101

1010

1011

-5

12

.
6

0110

1001

1010

-6

0111

1000

1001

-7

1000

0111

1000

-8

1111

10000
(, ,
"")

0000

.
16 , - 8 7
0 . , , . , .
,
26 ( 1).

3. : ,
:
1. ;
2. ;
3. ;
4. ;
5. .


- . .
. - , , ..
. .
( Edit ) (. , .74) :
<Ctrl> + <K><R> - , ;
<Ctrl> + <K><W>- .

1. :
;
<Ctrl>;
<Ctrl>, <K>;
<K>, <Ctrl>,
.

2. . .

13

.
1. . . "
, ( ) - 10 . .
(14521519).
1642 (16231662).
(19051957)
"" , . : , ;
; , ".
2. .
3. ( ,
, ).
4. ( ,
, ).
5. ( , , ,
,
).

(
Window ). - .
. , .
.
Tile
Cascade
Close All
Size / Move
(<Ctrl>+ F5>)

;
;
.
, .
.

<Shift> + <
>, < >, < >, < >. < >, < >, < >, < >. <Enter>.
.
Zoom (<F5>)
Next (<F6>)
Previos (<Shift> + <F6>)
Close (<Alt> + <F3>)
List

;
;
;
;
.

14

.
:
1. .
2. .

1. pr3_1 (, , , ).
Program pr3_1; Uses Crt;
Var r0, r1, r2, r, r4, r5, r6 : Integer;
Begin
ClrScr;
WriteLn ( ' 2 ' );
r0:=1; r1:=2; r2:=r1*r1; r3:=r2*r1; r4:=r2*r2; r5:=r3*r2; r6:=r*r;
WriteLn ( ' = ', r0 ) ;
WriteLn ( ' = ' , r1 );
WriteLn ( ' = ', r2 );
WriteLn ( ' = ', r);
WriteLn ( ' = ' , r4);
WriteLn ( ' = ' , r5);
WriteLn ( ' = ' , r6);
ReadLn
End.
.
. , r2:=r1*r1, ,
. WriteLn.
5- 4 :
r3 2 , r2 - ,
5
- 4 . 2 ?

,
10- .
2. pr_2 (, , , ).
. .

Program pr_2; Uses Crt;


Var r0,r1,r2, r , r 4 , r 5 , r 6 : Integer; s0,s1,s2,s3,s4,s5,s6 : Integer;
a,b,rez : Integer;
one,dec,hun : Integer;
Begin ClrScr;{ }
{ }
r0:=1; r1:=2; r2:=r1*r1; r3:=r2*r1; r4:=r2*r2; r5:=r*r2; r6:=r*r;
WriteLn ( ' , 128 64');ReadLn ();
b:=a; { }
s0:=b Mod 2; b:=b Div 2; s1:=b Mod 2; b:=b Div 2;
15

.
s2:=b Mod 2; b:=b Div 2; s3:=b Mod 2; b:=b Div 2;
s4:=b Mod 2; b:=b Div 2; s5:=b Mod 2; b:=b Div 2;
s6:=b Mod 2; b:=b Div 2;
b:=a; { }
one:=b Mod 10; b:=b Div 10;
dec:=b Mod 10; b:=b Div 10;
hun:=b Mod 10;
WriteLn ( ' ' );
Write(' - ');
WriteLn(hun*100+dec*10+one);
WriteLn (hun,dec,one);
WriteLn ( ' ' );
WriteLn (s6,s5,s4,s3,s2,s1,s0);
WriteLn ( ' ' );
rez:=s6*r6+s5*r5+s4*r4+s3*r3+s2*r2+s1*r1+s0*r0;
{}
WriteLn { ' , ' ) ; Writeln (a,' ', rez);
Readln
End.
, 128.
? , .

1. . , ( ,
). , ,
( ). , [10] , 10- . , , . - - ( .)
, ,
() . ,
, . -
, . , , .
2. pr_1 , .
3. pr_2 , .
4. . -
4 . 7-3, 7 + (-3). 0111 + 1101 = 10100. - 7,
- -3 . , 4
, , 0100, 4.
. 2 -5, 2 + (- 5). 0010 + 1011 =
1101, - 3 .
16

.
5. 6 . , . .
6. , ! ,
.
. ? !
205 405, .
7. , "*". 1**1 + 0011
= 1100. .
8. , 43015 ?
43005 43405.
9.
.
10. 3124 728. , 124, 128?
11. ,
: 3 + 4 = 7 , 4=13x 39x + 29= 70? .
12. -
: 600x= 211x + 252x + +53? .


: ?
. .
, , , ?. ( .. , 1999.). , ,
. . , , (.
. .., .34).
,
. ? - .
? - , .
? - .
?. ,
. . , , .
: , , .
, , !
. ,
, , , , ,
. , .
.. (),
: = 50% + 30% + 10% + 5% + 5%,
- , , - , - , 3 - , - .
, , 5%, , .

17

.
"".
, ,
:
();
1. (, , );
2. ();
3. ().
:
4. ();
5. ();
6.
().
, , , , , , , -
.
, , , 1975 , . , ,
, " ". ()
, "", ( ). ,
, . , , .
, - , , .

4. :
:
1. (. 1, . 22 23; 38 - 40);
2. ;
3. ( ,
);
4. :
/;
;
;
.

. Boolean. : False
() True () (False True - ), 1 . : False < True,
Ord(False)=0,
OrdTrue)=1,
Succ(False)=True,
Pred(True)=False.
: , , , - or; , , - and;
- not, " " ( ) - or.
(. . 39). 18

.
),
.
.
,
(): < (), > (), <= ( ), >= (
), <> ( ), = () . True,
, False .

Read. Write.
. : shl shr - .
m shl m
n ; m shr m
n . , , , , . , 32,
64, - 16.
.

1. Pr 4_1 (, ,
, ).
Program Pr4_1; Uses Crt;
Var a,b:Boolean;
Begin
ClrScr;
a:=True;b:=True; WriteLn (a : 6, b : 6, a and b : 6);
a:=True;b:=False; WriteLn (a : 6, b : 6, a and b : 6);
a:=False;b:=True; WriteLn (a : 6, b : 6, a and b : 6);
a:=False;b:=False; WriteLn (a : 6, b : 6, a and b : 6);
ReadLn
End.
. . a:=True; b:=True; WriteLn (a : 6, b : 6, a and b : 6);
, 3 .

, .
2. Pr 4_2 (, , , ).
Program Pr4_2; Uses Crt;
Var m, n : Integer;
19

.
Begin
ClrScr; WriteLn (' , ' ); ReadLn (m, n);
WriteLn (' ', n, ' ' ,m, ' ' , m shl n);
WriteLn (' ' ); ReadLn (m, n);
WriteLn (' ' , n, ' , ' ,m, ' ' , m, shr n);
ReadLn
End.
m = 32, n = 1 64 ( ) 16
( ). . , -1 1
, -2 32 767. ,

. 16 ( Integer), 4. -1
11112, 01112, ,
710.
3. pr4_3,
WriteLn.
Program Pr4_3; Uses Crt;
Begin ClrScr;
WriteLn (1365 and 2730); WriteLn (1365 or 2730); WriteLn (1365 xor 2730);
WriteLn (1365 and $FF); WriteLn (1365 and $FF0); WriteLn (1365 and $FF00);
ReadLn
End.
Integer ,
.
1365 2730? :
136510 = 0101010101012, 273010 = 1010101010102 ( 12
). and 0, or
r - 4095. . , , -256
and 255 = 0 -256 or 255 = -1 -256 xor 255 = -l. .
WriteLn. 10, 11, 12, 13, 14, 15 , , , D, , F. F = 11112.
$ , () . . , 85, 1360, 1280.
.

1. /.

20

.
: ,
.

1. , . , , READLN.
2. ,
. .
3.
- ,
. : WRITELN( K, L, M ).
4. : , .
1

TRUE

FALSE

TRUE

TRUE

FALSE

21

TRUE

TRUE

FALSE

FALSE

TRUE

10

2. .

:
1. y = f(x) x trunc(y), frac(y), round(y),
int(y).
2. , (x,y) TRUE,
, FALSE, .
.
:
1. .
2. .
3. .
4. .
:
1. , , .
2. (x,y) ,
WRITELN.
3 . .
:
1
1. Y = 2 x x + 4 x X = 4,741;
22

.
2.

: (0,5; 0,5). .1.

2
1. Y = 3 e x sin x X = 2,312;
2. : (1,5; 0,5). .2.
3
1. Y = x 1 + sin x X = 12,7409;
2. : (0,2; 0,9). .3.
4
1. Y= x*cosx + sin3x X=32,872;
2. : (0,75; 0,3). .4.
5
1. Y= tgx + |x| X= 2,6312;
2. : (0,2; 0,45). .5.
6

1 1
X= 0,387;
+
x x2
2. : (0,5; 2,5). .6.

1. Y = 1 +

7
1. Y=ch |x+1| X= 4,352;
2. : (0;0). .7.
8
1. Y=sinx + x2 X= 0,112;
2. : (1; 1,5). .8.
9
1. Y= sin arctgx X= 0,7129;
2. : ( 0,5; 0,9). .9.
10
1. Y= 5arctgx X= 4,4172;
2. : (1,5; 0). .10.
y

2
1
-2 -1 0

1 2

. 1

-2

1
-1 0
-1
-2
. 2

23

-1

-1
. 3

.
y

2
1
0 11

1
x

-2

0
-3

. 8

2
1

. 10

.9

1 2

. 7

-2 -1 0

.6

-3

. 5

2
-1

. 4

-2

-2

1
-1 0
-1
-2
.11

-1

-1
.12

5. :
:
1. () ;
2. :
( ).


1. (. 1, . 54: pr5_1,
Prim5_1.Pas). ; end else. ,
'Error 113: Error in statement. ()
If - Then - Else , ";" .
24

.
2. () , z. , . ,
.

:
Program pr5_2;
Var x, , z : Integer;
Begin
WriteLn ( ' ' ); ReadLn (x, , z);
(* *)
If (x>y) And (x>z) Then WriteLn (x)
Else If (y>x) And (y>z) Then WriteLn (y)
Else WriteLn (z);
(* *)
{ If x>y Then If x>z Then WriteLn (x) Else WriteLn (z)
Else If y>z Then WriteLn (y) Else WriteLn (z) ; }
(* *)
{ ????????? }
End.
. ,
. , . ,
. ,
, . ,
.. .
(* *) .


1. , :
a + b , a -
c=
a b, -
2. , (x, ),
, x 0.
3. . :
;
X, ;
;
;
25

.
5.
4. ,
.
5. , .
6. . , (""), .. , .
7. N. N,
, - " N ".
8. . ,
.
x - 12, x > 0
x 2 + 5, x > 3

9. : Y = 5 , x = 0 ; Z =
x - 8 , x <= 3
x 2 , x = 0

10. , . ,
, .
11.
.
12. () ,
, D.
13. () . :
5;
4 7;
3, 5, 7.
14. . - . . ,
.
15. . , . , 18 .
16. , y, z . : max(x
+ y + z, xyz) + 3; min (x2 + y2, y2 + z2) 4.
17. ,
, .
18. (, b) (, d). ,
?
19. , ,
(. 1).
(. 2).

. 1

. 2

20. , , b
( ). ,
, . -

26

.
. . ( " "). 10 ,
.


: .
:
( , , ). .
:
1. .
2. - .
3. .
4. , , .
:
1. .
2. .
3.
.
1: ax2 + b = 0.
2: ax2 + bx + c = 0 .
3: ax2 + b > 0.
4: ax2 + b 0 .
5: ax2 + bx + c > 0 .
6: ax2 + bx + c 0.
a x + b1 y + c1 = 0
7: 1
a 2 x + b 2 y + c 2 = 0
a x + b1 0
8 1
a 2 x + b 2 0


a x + b1 > 0
a x + b1 < 0
9 1
10 1
a 2 x + b 2 < 0
a 2 x + b 2 < 0


1. : -
, , .
?. .
, .
- , , . ,
: ,
.
- .
, , . , , , 27

.
, ,
. ? , ,
. -
,
.
(), ( ), , , .. , . ,
, , ,
. ,
, ,
. ,
.
, -
.
2. . ,
. , . .
, , .., -
. , , .
? . , , .
10 000 ,
.

()

1000

10 000

100 000

1 000 000
10 000 000

. , , ,
.
? - " ". .
, , - .. . ,
, ,
. .
- - , 28

.
. , , - .
3. .
( 1945- 1959 ). 50
, - . .
: - , - , - . ,
, , . , 05 825 631
( 05), 825 631.
. . . , (!).
.
.
. ADD () PR1, ZET, ADD - , PR1, ZET - .
(), ,
, , . "" ,
. - , , , .
.
- .

6. : For
:
1. :
, ;
, .
2. :
.

For. For
, ().
( ). , . For ( , ). - For, "" For
Goto, Exit .. For
.

29

.
1. ( <= 9999). , ( ), (, : 2222; 6161; 0440).
, For 1 4. ,
. r "". : r:= 10*r + m Mod 10 ( - "" ) m: = m Div 10 (
). .
i

- 3994
1 399
2 39
3
3
4
0

R
0
0 10 + 3994 mod 10 = 0 + 4 =
4
4 10 + 399 mod 10 = 40 + 9 =
49
49 10 + 39 mod 10 = 490 + 9 = 499
499 10+3 mod 10 = 4990 + 3 = 4993

Program pr6_1;
Var n, m, r, i : Integer;
Begin
WriteLn (' , 10 000'); 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.
,
LongInt.
2. , k (, k <= 9999). k ,
. , 6766, 5444, 0006, 0060 . ,
, .. , .

1
2
3
4

2 3 4

X X X

X X
X

X
X X

X X X

k 3732 3740. a1, a2


a3, a4 i.
30

.
i

3732

3733

3734

3735

3736

3737

3738

3739

3740

Program pr6_2;
Var n, k, i, a1, a2, a3, a4, m :Integer;
Begin
WriteLn (' , 9999'); ReadLn (n, k) ;
For i:=n To k Do
Begin m : = i ;
{ : a1 - , a2 - , - , 4 - }
a4:=m Mod 10; m:=m Div 10;
a3:=m Mod 10; m:=m Div 10;
a2:=m Mod 10; a1:=m Div 10;
If ((a1=a2) And (a1=a3) And (a1<>a4))
{1- }
Or ((a1=a2) And (a1=a4) And (a1<>a3)) {2- }
Or ((a1=a3) And (a1 = a4) And (a1<>a2)) {3- }
Or ((a2=a3) And (a2=a4) And (a2<>a1)) {4- }
Then WriteLn (i : 5)
End;
End.
4, 5 6- .
, , .
. ,
.

1. , N N.
2. = ((...(202 - 192)2 - 182)2 - ... 12)2.
3. ,
: 12= 1; 22 = 1 + 3; 32 = 1 + 3+ 5; 42 =1+3 + 5 + 7; .n2= 1 + 3+ 5+ 7+ 9+ ...
+ (2n - 1)
4. ,
N.
5. 25 55.

31

.
6. , 13.
7. , : , .
8. ,
, .
9. , 133
125, 134 111.
10. , 100.
11. , 4 ( ).
12. , 20, 100, 3 2, 4 8.
13. ,
7, . .
14. 7, 7.
.
15. , .
16. , q,
(0 < <= 18).
17. n. 0 5,
. , 1509 19.
18. , , n- , (, 153 = 13 + 53 + 3).
- .
19. 20 .
.
20. . .


: FOR.
:
C f(x) [a,b] x=a+ih,
h=(b a) / m, m - (i = 0, ... , m).
: 1) ; 2) : 3) .
:
1) x
.
2) h .

.
1:
2:
3:
4:
5:
6:
7:
8:
9:

f(x) = arcsinx,
f(x) = arccosx,
f(x) = ctgx,
f(x) = tgx,
f(x) = sinx + cosx,
f(x) = cosx + ctgx,
f(x) = tg(x/2),
f(x) = tg(x/2)+cosx,
f(x) = ctg(x/3)+sinx,

[0;1],
[0.5;1],
[/4 ; /2 ],
[0;/4],
[0; /4],
[/4; /2],
[0; 2/3],
[/2; ],
[/4; /2],

32

m = 20.
m = 10.
m = 15.
m = 10.
m = 20.
m = 10.
m = 15.
m = 20.
m = 10.

.
10: f(x) = arctgx,
11: f(x) = arcsinx,
12: f(x) = arccosx,

[2;7],
[0;1],
[0.5;1],

m = 15.
m = 20.
m = 10.


. , . ( - IBM/360) . , . - . .
FORTRAN I, ALGOL-58 , :
(FORTRAN II); (ALGOL-60); (COBOL); (Lisp).
: PL/1 (FORTRAN + ALGOL + COBOL), ALGOL-68 (
ALGOL-60), Pascal ( ALGOL-60), Simula (, ). ( ) .
, . :

;
;
.
,
,
.
. () , . ,
. ( , -2).
.. 1965 , Goto . , , Goto.
- . :
( .. , , , );
, ,
. ,
(, ) ,
.

(.
, . 26 -31). , (); (); , , ().

33

.
)

( );
;
;
;
;
;
.
,
"" , .. (, if-then-else, do-while) . , . 29 - 31.
(
, , .. , ) . , .
. , . ,
. computer science : , - , , , , , , (. .. , . 64).
: . , , ,
, . ,
.
. (, ). ,
,
. , .
, . , , - .
( , , ) .
, , , , .

34

.
7. : While
:
1. (. . 56 1);
2. :
;
n 1.
3. :
.


1. n. .
n ,
While. For
, , .
. (k) .
(m) 10 ,
(). .., .
, .
65387, m,
(k) 0. , , :
k
0
1
2
3
4
5

m
65387
6538
653
65
6
0

k 5, 5 . pr7_1 : , , , .
Program pr7_l;
Var m, n : LongInt; k: integer;
Begin
WriteLn (' n<>0 ' ); ReadLn (n);
m:=n; k:=0;
While m<>0 do begin Inc(k); m:=m div 10; end;
WriteLn (' ' ,n, ' - ' ,k, ' ');
ReadLn
End.
pr7_1, :

;
, 7265 7;
35

. , 12345, 54321;
;
;
, 5;
, ?
5 ( ), .

2. pr7_2 . n 1.
, n. , n , .. . ,
() n . While
, .
Program pr7_2;
Var n : Integer;
Begin
WriteLn (' n: ' ); ReadLn (n);
Write(n);
While n<>1 do
begin If n mod 2 = 0 then n:=n div 2 Else n:=(3*n+1) div 2;
Write( ,n);
end;
ReadLn
End.

n 2 20. ,
. , 8421, 58421,
126358421.
(n) , Integer?
-
?

1. :
a:=1; b:=1;
While a+b<8 do begin a:=1; b:=b+2 end;
S:=a+b
While? a, b, S ?
2. a b :
a:=1; b:=1;
While a<=3 do a:=a+1; b:=b+1.
3. s :
S:=0; I:=0; While I<5 do inc(i); s:=a+100 div i ;
36

.
S:=0; I:=1; While I>1 do begin s:=s+100 div I; dec(i) end;
4. ( 5) f n:
k:=1; f:=0; While k<n do f=f*k k:=k+1; .
5. , n , . p:=n;
While p>=0 do begin a:=a+p mod 10; p:=p div 10 end;
6. , 300, 19.
7. 1 n. , n =3456,
n=134561.
8. . , 8547
7548.
9. n . , 1903
19031903.
10. , 3.
11. , , , ,
.
. , , , .
12. ,
. , 76431 , 6331, 9782 .
13. , 0.
2. :
;
;
(3, -2, 4, -5, 0 ; 5, -4, -7, 8,
0 )
14. , . , 581088 3 , 4537 1 .
15. , .


:
f(x,y) [a,b]
h1 y [c,d] h2.

: 1) ; 2) ; 3) .
:
1. x, y
.
2. x , y - , , , -
.
3. , *.
1:
2:
3:
4:
5:

f(x,y) =x ln(x+y),
f(x,y) =sinxy / xy,
f(x,y) = (ex+y 1) /(x+y),
f(x,y) = (x3 1) / (y3 1 ),
f(x,y) =y lnxy,

[0;10],
[-5;5],
[0;5],
[0;10],
[1; 21],

37

h1=1,
h1=1,
h1=0.5,
h1=1,
h1=2,

[0;6],
[2;5],
[3;6],
[0;6],
[0;3],

h2=2.
h2=1.
h2=1.
h2=2.
h2=1.

.
6:
7:
8:
9:
10:

f(x,y) =sinln(x2 + y2),


[0;10],
2
2
2
f(x,y) =y ln(1 +x ) / (x +y ), [-5;5],
f(x,y) =cos(x+y) /(x2 1), [-10;10],
f(x,y) = (x3 +y3) / (ex 1),
[-2;2],
f(x,y) =xy / ln(1 +x2+y2),
[0;10],

h1=1,
h1=1,
h1=2,
h1=0.4,
h1=1,

[1;2.5],
[0;1.5],
[0; 1.5],
[-1;0.5],
[0;3],

h2=0.5 .
h2=0.5 .
h2=0.5.
h2=0.5.
h2=1.


- . 4- . .
, . . , , . , ( ), ,
- (
, 5.5, , ++).-
: , , .
. .
- , ,
, . .
.
, , ,
() ().
.
. , .. . , . :
, . . ,
.
- , . , . , . ,
, - ,
, , , - ( ). ,
, .
- .
.
- ,
.

38

.
- ,
. -
. (),
( , ),
. . () , , , .

8. : Repeat... Until
:
1. (. . 57 1);
2. :
;
;
2. .


, 1 . 1 .
: 2, 3, 5, 7, 11, 13, 17, 19, 23, 29, 31, 37, 41, 43, 47, 53, 59, 61, 67, 71, 73, 79, 83, 89, 97, ...

1. pr8_1 , .
2 div 2, 2 n (?).
Program pr8_l;
Var i, n : LongInt;
Begin
WriteLn (' '); ReadLn (n);
i : = l;
Repeat I:=I+1; Until (i > n div 2) Or (n mod i = 0);
If i > n div 2 Then Writeln (' ',n, ' '}
Else WriteLn (' ' ,i, ' - ' ,n, ', 1');
End.
While (. ). . , .
. Repeat ... Until ,
i > n div 2, If n
mod i = 0 Then WriteLn (..., i).
. > 1 .
.
39

.
( , , 101 120) ,
pr1_8, . : n = p1a1 p2a2 ...
pqaq - (ai >= 0), i - , , 168= 23 31 50 71.
2. () b - , . , . b : a = p1a1 p2a2 ... pqaq b = p1b1 p2b2 ... prbr - (,
b) : p1min(a1,b1) p2min(a2,b2) ... pmmin(am,bm).
, (.
). b a >= b. b = 0, (, b) = a, b <>0,
, b r, r - b, (,
b) = (b, r). , r = a mod b = - (a div b) b. -
, b, , r b. , = 48, b = 18.
:
a

48

18

48 mod 18 =12 18

(48, 18) = (12, 18)

12

18 mod 12 = 6 (12, 18) = (12, )

12 mod 6 = 0

(12, 6) = (0, 6)

(0, 6) = 6

, (48, 18) = 6.

Repeat ... Until :
Program pr8_2;
Var a, b: LongInt;
Begin
WriteLn (' <>0'); ReadLn (a, b) ;
Repeat If a>b Then a:=a mod b Else b:=b mod a Until (a=0) or (b=0) ;
WriteLn ('=', +b) ;
ReadLn
End.
, Repeat . . . Until While. ?
i
1 = 1 + 1 = 2, 2 = 2 + 1 = 3, 3 = 2 3 + 1 = 7, 4 = 2 3 7 + 1 = 43,
5 = 2 3 7 43 + 1 = 1807, 6 = 2 3 7 1807 + 1 = 3263443,
7 = 2 3 7 1807 3263443 + 1 = 547 607 1033 31051 ..
40

.
. ,
. , 5 -1807 = 13
139. , - (ei, j) = 1
ij. pr8_2 . pr8_1, , 6 .
3. . b
, , , (, b) =
+ b . , ,
, (, b) . , 6 = (12, -30) = 12 3 + (-30) 1 = 12*(-2)+(-30)*(-1).
:
* a0 = a , a0 = a x0 + b y0, x0 = 1, y0 = 0;
* a1 = b, a1 = a x1 + b y1, x1 = 0, y1 = 1;
* a2 = a0 - a1 q1, q1 = a0 div a1; a0 a1 :
a2 = a x0 + b y0 - (a x1 + b y1) q1 = a (x0 - x1 q1) + b ( y0 - y1 q1) =
a x2 + b y2
* a3 = a1 - a2 q2, q2 = a1 div a2 a1 a2 :
a3 = a x1 + b y1 - (a x2 + b y2) q2 = a (x1 - x2 q2) + b (y1 - y2 q2) =
a x3 + b y3;
* ...
* ai = ai-2 - ai-1 qi-1, qi-1 = ai-2 div ai-1, ai = a xi-2 + b yi-2 - (a xi-1 + b yi-1) qi1 = a xi + byi;
* ...
* 0 = ak-1 - ak qk, qk = ak-1 div ak, ... 0 = a xk+1 + b yk+1.
qi, ai, xi , yi, :
qi-1 = ai-2 div ai-1; ai = ai-2 - ai-1 qi-1; xi = xi-2 - xi-1 qi-1; yi = yi-2 - yi-1 qi-1;
= 48 b= 18.
i

ai

xi

yi

qi

48

18

12

-2

-1

d = (48,18) = 6 6 = 48 (-1)+18 3.
pr8_3.
Program pr8_3;
Var a, b, a0, a1, x0, x1, y0, y1, q, t : Integer;
Begin
WriteLn(' , '); ReadLn(, b) ;
a0:=a; a1:=b; x0:=1; x1:=0; 0:=0; 1:=1;
Repeat
q:=a0 div a1;
t:=a0; a0:=a1; a1:=t-a1*q;
t:=x0; x0:=x1; x1:=t-x1*q;
41

.
t:=y0; y0:=y1; y1:=t-y1*q
Until a1=0;
WriteLn (a0, '=',, '*(', x0,') + ',b,' * (', y0, ') ');
ReadLn
End.
, , .

1. 2P - 1, - , M. (1588 -1648.).
2, 3, 5, 7, 11, 13, 17, 19, 23, 29, 31 ? .
: (
), , .
2. , b, . , , .
( ), ..
: + b = , - b , , d = (, b) . ,
x0, y0 - () , : =x0-n(b div
d),=y0+n(divd) . : 12 - 30 y = 84. (12, -30) = 6. 84
6. . (, ) = (2, -2).
: =2+5n,=-2+2n.
3. a b - , (, b) = | b| div (a, b).
. b - . > 0 () b, , b , , a, b, .
4. (fn) : f0 = f1 = 1; fn = fn-1 + fn-2 n >= 2. : 1, 1, 2, 3, 5, 8, 13, 21, 34, 55, 89,... :
o ,
Integer (LongInt);
o s - , , s
Integer (LongInt).
5. , , . , ,
, . : 6 = 1 + 2 + 3, 28 = 1 + 2 + 4 + 7 + 14. (.
, 2p-1 (2p - 1) , (2p
1) - . . ,
,
.
6. , . :
52 = 25, 252 = 625. , 1, 5, 6. (
), 999 ( , 9992 = 998001).
7. . , 3 =
216. , 1, 5, ?
42

.
.


1. .

.
. ,
, ISO / IEC 12207 (ISO - International
Organisation of Standardisation - , IEC International Electrotechnical Commission - ).
, : 1) (, , , , ); 2) , (, , , , , , ); 3) ( ,
, ). : . , . . , , .

. . , . , , . ""
.
2. , . .
. . ,
, , . . , , , .
. , .
, . , . . , , .
3.

Run/Run

<Ctrl> + <F9>

43

.
Run/Go to cursor

<F4>

Run/Trace into

<F7>

(), . ,

Run/Step over

<F8>

Debug/Watch

( Watches)

Debug/
Breakpoints

Debug/Evaluate...

<Ctrl> + <F4>

Evaluate and Modify.


(
)

Debug/Add
watch

<Ctrl> + <F7>

Add watch
.
:
Watch <Insert>
<Delete>

Debug/Add
breakpoint

<Ctrl> + <F8>

( )

9. :
:
1. ;
2. ( )
1k + 2k + ... + nk ;
;
, ;
, ;
, 3, 153;
3. .

, (). .
, , (For,
While, Repeat ... Until).

44

.
1. n k. 1 k + 2 k + ... + n k . For i, 1
n. y = ik
s = s + y.
Program pr9_1;
Var n, k, y, i, s, j : Integer;
Begin
WriteLn (' n k '); ReadLn (n, k);
s:=0;
For i:=1 To n Do Begin y:=1; For j:=1 To k Do y:=y*i; s:=s+y End;
WriteLn (': ',s)
End.
.
, 4.
Debug/Watch. Watches.
<Insert> ( Add Watch), (n, k, s, i, j, y).
Watches . , . Window/Size/Move (
<Ctrl> + <F5> ) <Shift> + <> ,<> , <>, < >
<> ,<> , <>, < > .
Run/Step over (<F8>).
Begin . <F8> ( ).
(
<F8>),
Watches. ReadLn (n,k) , ,
4 2, For .
.
s:=s+y.
Debug/Add Breakpoint (<Ctrl> + <F8>). . , .
(<Ctrl> + <F9>). .
( <F8>).
Debug/Evaluate... Expression Evaluate and
Modify s. Result
s, 1.
.
s 5.
45

.
:

.
2. , 11 + 22 + ... + nn .
3. k , , 5.
n, Integer .
4. - . ,
. ,
().
. , 34 697 2 (3 + 4 +
6 + 9 + 7 = 29; 2 + 9 = 11; 1 + 1 = 2).
.
Program pr9_2;
Var n, k, s : LongInt;
Begin
WriteLn (' '); ReadLn(n);
s:=n;
While s>9 Do Begin k:=s; s:=0;
Repeat
s:=s + k mod 10;
k:=k div 10
Until k=0
End;
WriteLn (' ',n,' ',s)
End.
5. . , ,
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,..0k20,
200 , .. 0 t 200. , :
Program pr9_3;
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.
46

.
(
If)? b 11 (
0 10), b k 0
20, k t 0 200.
, 1121201=46431 . ,
t = 100 - (b + k) t .
Program Pr9_3m;
Var b, k, t: Integer;
Begin
For b:=0 To 10 Do
For k:=0 To 20 Do
Begin t:=100-(b+k); If (20*b+10*k+t=200)
Then WriteLn ('', b,' ',k,' ',t)
End
End.
1121 = 231 .
.
6. , abcd (a, b,
c, d - , ), : ab - cd = a + b + c + d. , , , . . ,
. :
10*a+b(10*c+d)=a+b+c+d 9(a - c) = 2(c + d) (a-c)/(c + d) = 2/9, a
= c + 2, d = 9 - c 0 c 7.
Program pr9_4;
Var a, b, c, d:Integer;
Begin
For c:=0 To 7 Do
Begin a:=c+2; d:=9-c;
For b:=0 To 9 Do If (b<>c)and(b<>a)and(b<>d)
Then WriteLn (a,b,c,d)
End
End.
7. , 3.
. .
.. ,
153.
Program pr9_5;
Var n, m, t, s, q:LongInt;
Begin
WriteLn (' n=); ReadLn(n);
47

.
Writeln ( 3 ); m:=3*n;Write(m,'':3);
Writeln( ');
Repeat
s:=0;t:=m;
While m>0 Do Begin q:=m mod 10; s:=s+q*q*q; m:=m div 10 End;
m:=s; Write (m,'':3)
Until m=t; writeln; ReadLn
End.

1. :
a:=1; b:=1;
For i:=0 To n Do
Begin For j:=1 To b Do Write ('*');
WriteLn;
c:=a+b; a:=b; b:=c
End;
n = 6? ?
2. :
b:=0;
While a<>0 Do Begin b:=b*10+a mod 10 a:=a div 10; End;
Write (b);
= 13305? ?
q. , q .
4. 1 n.
, . , n =
4, :
1+
2++
3++
4+++
5. n. ,
? , :
x, y, z , x2 + y2 + z2 = n;
x, y, z , x2 + y2 + z2 = n.
6. 1 10 000 .
7. a, b (a < b). p,
: a p b.
8. n, m. , n,
m.
9. n m. , n m. ,
( ).
10. ,
, .
11. , k- :
12345678910..., ;

3.

48

.
14916253649..., ;
1123581321., .
12. , :
13 = 1
23 = 3 + 5
33 = 7 + 9 + 11
43 = 13 + 15 + 17 + 19
53 = 21 + 23 + 25 + 27 + 29
13. n, m, k , n2 + m2 = k2 [1, 10] . . , n m, .
14. , :
p;
p, , ,
, ;
, 3;
1! + 2! + 3! + ... + n!;
xn , n - ;
x1 , x2 , x3 , ..., xn .
15. . ,
:
, ;
( ), .
16. M N. ,
, , , ,
.
17. N p. , N
p.
18. p q. q, p.
19. a b
: a2 + b2 = c2 . , , . , : a = uv; b = (uu - vv) div 2, c = (uu + vv)div 2,
- u v - u > v.
20. N,
x y (x y).
21. m, n1 , n2 , ..., nm (m 2). (n1 , n2 , ..., nm ), (n1 , n2 , ..., nm ) = ( (n1 , n2 , ..., nm-1 ), nm )
.
22. , 0 1,
7 ( - ).

49

10. : .
:
1. (. 2, . 7 - 25);
2. ;
3. :
, ;
;
;
;
;
4. .


:
Integer, Real Boolean. . , , ,
.
. , Integer, Real Boolean
.
,
. , , , , ( ). :
Type <_>=<_>;

: Var <_>:<_>;
. .
Program Pr10_1; Var a1,a2,a3,a4,a5,s: Integer;
Begin
WriteLn (' '); ReadLn(a1,a2,a3,a4,a5);
s:=a1+a2+a3+a4+a5; WriteLn (' ',s) ; ReadLn
End.
30
30 .

, . . .
30 .
, 30 .
Type Vector = Array [1..30] Of Integer;
Type, .
50

= ( ). Vector ;
Array ( , ); [1..30] , , , ; Of
; Integer . :
Program Pr10_1m;
Const n=30;
Type Vector=Array[1..n] Of Integer;
Var A : Vector; s,i: Integer;
Begin
WriteLn (' ',n, ' ');
For i:=1 To n Do Begin write(A[,I,]=); ReadLn (A[i]); end;
s:=0; For i:=1 To n Do s:=s+A[i]; WriteLn (' ',s);
End.

1. , .
.
, . : WriteLn(' '); ReadLn(k);
If A[i] Mod k=0 Then s:=s+A[i];
. n ( 30 ).

,
.
( pos, neg)
. ?
pos, neg:Integer;
pos:=0;neg:=0;
If A[i]>0 Then Inc (pos) Else If A[i]<0 Then Inc (neg);
WriteLn(pos:4,neg:4);
, .
, B
A.
B B.

51

A ( ),
B.
. , ,
!

Program Pr10_2;
Const n=10; Type Vector=Array[1..n] Of Integer;
Var A,B: Vector; i,j : Integer;
Begin
WriteLn (' ',n, ' ');
For i:=1 To n Do Begin write(A[,I,]=); ReadLn (A[i]); end;
j:=0; For i:=1 To n Do If A[i] mod 2 =0 Then Begin Inc(j); B[j]:=i End;
For i:=1 To j Do Write (B[i]:3); WriteLn;
End.
2. , ,
, ( ).
:
k:=0; For i:=1 To n Do If A[i]<0 Then k:=i;
If k=0 Then < >
Else < i >;
:
, , . ,
, , ,
. Computer Science , .
If A[i]<0 Then Begin k:=i; Break End;
,
,
. , . Break, Goto .
. , . :
i:=n; While (i>=1) And (A[i]>0) Do Dec(i);
If i<1 Then < >
Else < i >;
. . For, .
{$R+}
Program Pr10_3;
Const n=7;
Type Vector=Array[1..n] Of Integer;

52

Var A:Vector; i:Integer;


Begin
WriteLn (' . .');
For i:=1 To n Do Read (A[i]);
WriteLn (' ()');
For i:=1 To n do If A[i]<0 Then WriteLn (A[i]:5,i:5);
End.
: For i:=1 To n
n n+1 {$R+}.
: Error 201: Range check error. , i ( A)
, .. n.
.
$ ,
( ), . / {$R+}/{$R-}. {$R+}
,

.
.
. .
3.
. .
. ( ), ,
, .
Random. .
{$R-}
Program Pr10_4;
Const n=10;
Type Vector=Array[1..n] Of Integer;
Var A:Vector; i:Integer;
{Randomize;} WriteLn (' A');
Begin
For i:=1 To n Do A[i]:=Random (21) {-10};
WriteLn (''); For i:=1 To n Do Write (A[i]:5);
ReadLn

End.
.
0 20.
(-10) . ,
53

-10 10. .
, , -17 25. . Randomize. . . ? , Random, (- ) .
( Randomize),
. {$R+}. :
Error 201: Range check error.
Random
.
:
{$R+}
Program Pr10_4m;
Const n=10;
Var i:Integer;
Begin
WriteLn (' 10 10 10');
For i:=1 To n Do WriteLn (Random (21)-10);
ReadLn
End.

-10 10, - . ,
, : 65530, 1, 2, 4, 65527, 2, 65528, 65534, 3, 2. ? ,
Word 0 65535 6553510 = 216 -1
= 11111111111111112 , -1 . 65534 -2 .
Random Word. Integer.
, ,
2, LongInt.
Integer. - . A
LongInt .
, , ( )? Integer
: For i:=1 To n Do A[i]:=
Integer (Random (21)-10;
4. N. N 123(N-1)N ( N!).
, 8! = 40320, 13! = 6227020800. ,
Integer, LongInt -

54

. . :

A[0] A[1] A[2] A[3] A[4] A[5] A[6] A[7] A[8]


8
0
0
8
6
1
9
9
3
11! = 39916800. A[0] , A[1] , A[2] , A[3] - .. ,
?
.
, , Watch,
,
N.
.
{$R+}
Program Pr10_5;
Const MaxN=300;
Type Vector=Array[0..MaxN] Of Integer;
Var A:Vector; i,j,r,w,N:Integer;
Begin
FillChar (A,SizeOf (A),0); { }
Write(' , '); ReadLn(N);
A[0]:=1;A[1]:=1;j:=2;{ , 2!}
While (j<=N) nd (A[0]<MaxN) Do
Begin { .}
r:=0;i:=1;{r
j A[i] }
While (i<=A[0]) or (r<>0) Do
Begin {
}
w:=A[i]*j+r;{
}
A[i]:=w mod 10;{ i}
r:=w div 10;{ .}
If A[A[0]+1]<>0 Then Inc(A[0]);{, ,
A, .}

Inc(i)
End;
Inc(j)
End;
For i:=A[0] DownTo 1 Do Write(A[i]);{ .} WriteLn;
ReadLn
End.
55

N, 300 A .
, 1 N.
, an , ,
3100 .

. :
1. , A (A );
2. , ( );
3. , , ;
4. ;
5. ;
6. c k1- k2-, k1 k2 ;
7. ;
8. ;
9. ;
10. , 3 5, ;
11. , , ;
12. ( , );
13. ;
14. , ;
15. , ;
16. , 10;
17. ;
18. ;
19. , ;
20. , 5;
21. , 3 5;
22. , ( );
23. ,
;
24. , .
:
1. ;
2. ?
() ;
3. , ? , ;
4. , k, k ;
5. , 5 2;
6. 2 ;
7. .
8.
N , : 135(2N-1), 2468(2N).

56

,
.
, .


1. .
, .. .
.
, ,
. . ? (). A: Array[1..10] Of Integer.

,
Addr(A[1])

10

Integer

A[i] : Addr(A[i])=Addr(A[1])+(i-1)*2

2. . .
. , , ,
. . . -
, , ..

. ,
. ,
. .
:
1. () ;
2. , ,
;
3. ;
4. , - ,
, ;
5. ;
6. ;
7. .

57

- , .
( - ), . , . N ,
0 N-1. .
k , 2k .
. ,
. ,
. ,
,
.
3. .
, .
40-
. . ()
. , , .
, ,
( ) . ,
.
.
(, ). ,
, . , . ,
.
. . 58

. ,
, .
. ,
.
4. 60- . , , . Informatique 6070- . Computer Science .
. , , .
,
. .
. ,
, .

11. :
:
;
, ;
, ;
:
a, b, c ;
y = an xn + an1 xn1 + + a2 x2 + a1 x1 + a0;
.

. , .
, , , , .
,
, ,
Type, Type Var. , ,
(. 1,
.9).
.
.
Procedure (<>);
Label <>;
Const < >;
Type < >;
Var < >;
< >;
Begin
< >
End;

59

. , .

. .

.
, .
.
Sum a, b, c.
x, y z. x, y Var, z - Var. : ax, by, cz.
Sum(a,b,c) a x Sum, b - y.
c z. Sum ,
c z
c. Var z.
.
, - .
, ()

End).
. . ,
( x, y, z -
). - ,
(a, b, c - ).
.
-. a b .

.
( ),
, 60

, (x,y -).
-. ,
Var.
, ( ). .
,
,
. ?
, ,
( - , ). , ,
(-, -).

, , .

1. a, b, c
, .. , a b c.
Program pr11_1;
Procedure Swap (Var x,y:Integer);
Var t:Integer;
Begin
t:=x; x:=y; y:=t
End;
{******* *******}
Var a,b,c:Integer;
Begin WriteLn (' '); ReadLn (a,b,c);
If a>b Then Swap (a,b);
If b>c Then Swap (b,c);
If a>c Then Swap (a,c);
WriteLn (a:5,b:5,c:5);
End.
. .
. , .
61

2. y = an xn + an1 xn1 + +
a2 x2 + a1 x1 + a0 , - . an , an1 , ,
a1 , a0 ,
(q) (d).
q, d, n, x . , q = 2, d = 3, n = 5 x = 4. 245 + 544 + 843 + 1142 + 1441 + 1740.
Program pr11_2;
Procedure Degree (x,y: Integer; Var st: Integer);
Var i:Integer;
Begin
st:=1; For i:=1 To y Do st:=st*x
End;
{******* *******}
Var q,d,n,x,t,w,s: Integer;
Begin
Writeln (' ');
Readln (q,d,n,x); s:=0;t:=n;
For i:=1 To n+1 Do Begin Degree (x,t,w); s:=s+q*w; Dec (t); Inc (q,d) End;
Writeln (' ',s); Readln
End.
q, t, w .
,
.
q, d, x (
) n,
Integer .
. x Degree
!

-: 17 + 4(14 + 4(11 + 4(8 + 4(5 + 42)))).


, , . : a0 + x(a1 + x(a2 + x( + x(an1 + xan )))). .
, .
4 25 + 48 + 411 + 414 + 417 + ?
? , . 4 2
, , .. . . 8 5 .
. . ,
.
: an x an1 + a2 xa1 + xa0 +. 62

Part, (
) .
Part.
Procedure Part (x,y:Integer; t:Byte; Var z:Integer);
Begin If t=1 Then z:=x+y Else z:=x*y End;
.
, . ?
3. (
) . .
Program Pr11_3;
Const n=8; l=-10; h=21;
Type Vector=Array[1..n] Of Integer;
Var A:MyArray;
Procedure Init (t,v,w:Integer; Var X:Vector);
Var i:Integer;
Begin Randomize; For i:=1 To t Do X[i]:=v+Integer (Random(w)) End;
Procedure Print (t:Integer; X:Vector);
Var i:Integer;
Begin For i:=1 To t Do Write (X[i]:5); WriteLn; End;
Begin
WriteLn (' A');Init (n,l,h,A);
{ n l h}
WriteLn (''); Print (n,A)
{n ( )}
End.
,
.
( , ), ,
.
Print :
Procedure Print (n:Integer; X:Array[1..n] Of Integer)
. : Error 54: OF expected.
, .. Array Of.
: Procedure Print (n:Integer; X:Array Of Integer). : Error 201: Range check error.
- {$R-}. , , . , .
.
4. . ,
.
63

Init , Print - . . Init Print .


( ) . .
,
.
, . , , , , , .
{$R+}
Program Pr_4;
Const n=10; la=-10; ha=21;
m=8; lb=-15; hb=31;
Type Vector=Array[1..n] Of Integer;
Var A,B,C:Vector; k:Integer;
Procedure Solve (qx, qy:Integer; Var qz:Integer; X,Y:Vector; Var Z: Vector);
Begin
End;
Begin Init (n,la,ha,A);
WriteLn (' A'); Print (n,A);
Init (m,lb,hb,B);
WriteLn (' B'); Print (m,B);
Solve (n,m,k,A,B,C);
WriteLn (' , , B');Print (k,C);
ReadLn
End.
, , Solve.
Procedure Solve(qx,qy:Integer; Var qz:Integer; X,Y:Vector; Var Z: Vector);
Var i,j:Integer;
Begin
qz:=0;
For i:=1 To qx Do
For j:=1 To qy Do
If X[i]=Y[j] Then Begin Inc(qz); Z[qz]:=X[i] {j:=qy} End
End;
,
. , , 10, . 10 , . j:=qy.
For j:=1
64

. . .
Procedure Solve(qx,qy:Integer; Var qz:Integer; X,Y:Vector; Var Z: Vector);
Var i,j:Integer;
Begin
qz:=0;
For i:=1 To qx Do
Begin j:=1;
While (j<=qy) And (X[i]<>Y[j]) Do Inc(j);
If j<=qy Then Begin Inc(qz); Z[qz]:=X[i] End
End
End;
5. A n m, 1 < m < n. , m ,
(m + 1)- n- , .
: m ,
, (m + 1)-. .
. n = 10, m = 6, A:
5 1 -4 3 7 2 -1 9 8 6
m
2 7 3 -4 1 5 -1 9 8 6
2 7 3 -4 1 5 6 8 9 -1
m + 1 n
-1 9 8 6 5 1 -4 3 7 2
1 n
Init Print. Rev
t l.
{$R+}
Program Pr11_5;
Const n=10;m=6;
Type Vector=Array[1..n] Of Integer;
Var A:Vector;
Procedure Init (Var X:Vector);
Procedure Print (X:Vector);
Procedure Swap (Var a,b:Integer); { .}
Procedure Rev (t,l:Integer; Var X:Vector);
Var i:Integer;
Begin For i:=t To t+(l-t) Div 2 Do Swap (X[i],X[l-i+t]) End;
Begin
Init (A); Print (A);
Rev (1,m,A); Rev (m+1,n,A); Rev (1,n,A); Print (A);
ReadLn
End.

1.

: y = an xn + an-1 xn1 + + a2 x2 + a1 x1 + a0 ,
z = bn xn + bn-1 xn1 + + b2 x2 + b1 x1 + b0 , - .
65

A B. x y z.
2. . ,
.
3. . ,
.
4. 4 .
5. 3 . ,
.
6. 3 .
7. .
. .
8. .
,
.
9. (A, B) n m.

( 5 ).
10. n. (1742
). ( )
, n, ,
. 2 n 999.
. : 6 = 3
+ 3 ; 12 = 5 + 7; 30 = 7 + 23; 308 = 31 + 277; 992 = 73 + 919
. n.
11. n:
2 , 2;
3 , 3;
4 , 4;
5 , 0 5;
8 , 4 8;
9 , 9;
11 , ,
, , , 11.
.
n.


1.

.
, ,
(), . , - ; -
; -
.. , , ,
. ; 1
6; 52 .
, ,
. , , -
. - 6, - 3. -

66

, - 52, - 13.
.
S, , . A - S . |A| / |S|, | | , A
P(A). : 0 P(A) 1.
:
10 4/36
= 1/9, 36 (5, 5), (5, 6), (6, 5) (6, 6).
, , ,
15/36.
92 100 .
92/100 (0,92).
1000 16 . 0,016.
0,8, - 0,7. , .
. 100 . 80 , 20 . 10 7 , 20
- 14 . , 100 94 .
- 0,94.
, 1, - .
, , . , 0, - .
( ) , - .
, , . A
B , .
. A B - , P(A + B) = P(A) + P(B). n . , A1 , A2 , , An , , , .
:
. , ,
.
- . 1 2 , 2 3 , 3 4 , 4 5 5 6 , .
- 36 . - , ,
, , , , , - .
- . ,
.
2. . , , . . , , , , .
- .
67

, -,
, , , , ,
.. ,
. . : , .. .
, - . . , -.
. ,
- . .
. - , , , , . , 16 ,
- 0 15.
, .
.
1- . 8 15? - (1).
2- . 12 15? - (0).
3- . 11 12? - (1).
4- . 11? - (0).
.
1- . 0 3? - .
2- . 12 15? - .
3- . 4 7? - .
4- . 8 11? - .
5- . 10 11? - .
6- . 11? - .
? , .
(1 ) , , , . , . - , 4/6 . 4 .
, . N
(t). t, I, log2N.
. 1928 . , .:
I = -(p1 log2 p1 + p2 log2 p2 + + pN log2 pN ), pi - .
. . pi = 1/N i.
, I=-(1/Nlog2(1/N)++1/Nlog2(1/N))=log2N. 0 1. 10102
, 10 - !
, , - (binary digit - ). -
, . ,
? , . : , ? ,
. , 68

(t1 t2) . - N1 N2 .
(x1, x2), - (N 1 N 2). ,
log2(N1N 2) , log 2 (N 1 N 2) .
, , t1 log2N1 , t2 - log2N2 . ,
log2N1 + log2N2 . , log 2 (N 1 N 2 ) = log 2N1 + log 2N2 ,
. .
. 27 : 26 , .
, ?
27 , , log227 . log23 . X ,
Xlog23 . , Xlog2 log227 = log233 = 3log23.
, X 3. 3 : 9 ,
3 , ,
3 . , 7 , , , 9 , - 4 ,
log27 + log29 .
, log2(79) , 6 . : log 2 (79) = log 2 7 + log 2 9 = 5,97728 < 6.
, log2N ? ,
, k , k (x1 , x2 , , xk ). Nk . ,
(sk ) :
log 2Nk < s k < log 2 N k + 1 log2N<sk/k<log2N+1/k. Sk / k ,
, , N . k , 1/k
. , , N , ,
N, log 2 N .

11. :

1. ;
2. , ;
3. :
n m;
;
4. .

. , , .
. ,
.
Function .
69

Function < > [(< >)]:< >;


, , - .
.

1. - C(n, m).
- Fact(n). C(n, m) = n! / m!(n - m)!.
Program Pr12_1;
{******** - n ******* }
Function Fact(n:Integer):Longint;
Begin
End;
{******** *******}
Var n,m: Integer; c: Longint;
Begin
WriteLn(' n m :'); ReadLn(n,m);
c:=Fact(n) / (Fact(m) * Fact(n-m));
WriteLn(c);
Readln
End.
( Fact ,
) c:=Fact(n) / (Fact(m) *
Fact(n-m)); - Error 26: Type mismatch. - . ,
, . / .
Div, ..
: c:=Fact(n) Div (Fact(m) * Fact(n-m));
.
Function Fact(n:Integer):Longint;
Var i: Integer; rez: Longint;
Begin
rez:=1; For i:=1 To n Do rez:=rez*i;
Fact:=rez
End;
n m. n = 10, m = 5 252 . n = 13, m = 5 399, -
... . n = 15, m = 7 9, , . .
? (
). () ? C(13,5) =12345678910111213) / ((12345)(12345678)).
70

(13, 5) , , ,
. 91113 = 1287.
. , .
C(13, 5), 1287, ,
.
Program Pr12_1m;
Function S(n,m:Integer):LongInt;
Var i:Integer; rez,cht:LongInt;
Begin
rez:=1;cht:=1;
For i:=1 To m Do Begin rez:=rez*i; cht:=cht*(n-i+1) end;
S:=cht Div rez
End;
{******** *******}
Var n,m:Integer;
Begin
WriteLn(' : '); ReadLn(n,m);
WriteLn(S(n,m));
ReadLn
End.
.
C(n, m), p1a1 p2a2 - pgag, ai 0, pi - . : 1 < n
100, 1 < m < n. - . . . C(8, 5) = 8! /
(5!3!). 8! , ,
Sn, Sn[i] = 1, i .
Sn, . i , . Sn, , , i,
Sn[i] . n!, m! (nm)!. .

Sn

Sm
Snm

\ i

8!

5!

3!

71

.
, C(8, 5) = 2371.

Program Pr12_2;
Const Q=100;
Type Vector=Array[1..Q] Of Integer;
Var n,m:Integer; P:Vector;
Procedure Solve(sn,sm:Integer; Var Sp:Vector);
Begin
End;
Procedure Print(pn:Integer;Pp:Vector);
Var i:Integer;
Begin For i:=2 To pn Do If Pp[i]<>0 Then WriteLn(i:5,Pp[i]:5) End;
Begin
WriteLn(' n m'); ReadLn(n,m);
Solve(n,m,P); Print(n,P); ReadLn
End.
Solve:
Procedure Solve(sn,sm:Integer; Var Sp:Vector);
Var i:Integer; Sni,Smi,Snmi:Vector;
Begin
Calc(sn,Sni);
{ , n!}
Calc(sm,Smi);
{ , m!}
Calc(sn-sm,Snmi); { , (n-m)!}
For i:=2 To sn Do Sp[i]:=Sni[i]-Smi[i]-Snmi[i]
End;
Calc, Begin End,
. Calc,
, , .
, .
. , 100.
Procedure Calc (n:Integer; Var X:Vector);
Var i,j,t:Integer;
Begin
FillChar(X,SizeOf(X),0); {SizeOf ,
X; FillChar .}
For i:=1 To n Do X[i]:=1; { , .}
For i:=4 To n Do
Begin t:=i; j:=2;
While (j<=(t div 2)) Do
If t Mod j=0 Then Begin {j t .}
Inc(X[j]); t:=t div j
If t=j Then Inc(X[j])
End
72

Else Inc(j);
If t<>i Then Begin { i.}
X[i]:=0;If (t<>j) Then Inc(X[t])
End

End
End;
n. n 10 000.
Integer LongInt, Error 202: Stack oferflow
error. .
, . .
{$R+}
Program Pr12_2m;
Const Q=10000;
Type Vector=Array[1..Q] Of Integer;
Var n,m:LongInt; P:Vector;
Procedure Inc_0(n:LongInt);
Var i,j,t:Integer;
Begin
For i:=2 To n Do
Begin t:=i; j:=2;
While (j<=(t div 2)) Do
If t Mod j=0 Then Begin Inc(P[j]);
t:=t div j;
If t=j Then Inc(P[j])
End
Else Inc(j);
If t<>i Then Begin If (t<>j) Then Inc(P[t]) End
Else P[i]:=1
End
End;
Procedure Dec_0(n:LongInt);
Var i,j,t:Integer;
Begin
For i:=2 To n Do
Begin t:=i; j:=2;
While (j<=(t Div 2)) Do
If t Mod j=0 Then Begin
Dec(P[j]);
t:=t div j;
If t=j Then Dec(P[j])
End
Else Inc(j);
If t<>i Then Begin If (t<>j) Then Dec(P[t]) End
73

Else Dec(P[i])

End
End;
Begin
WriteLn(' n m'); ReadLn(n,m);
Inc_0(n); Dec_0(m) Dec_0(n-m)
End.
, Inc_0 Dec_0 . .
. , Q , , 30 000. , n m
.
2. 11 ( 7) ,
.
.
Function Pal(n:LongInt):LongInt;
Var x:LongInt;
Begin
x:=0;
While n<>0 Do Begin x:=x*10+n Mod 10; n:=n Div 10 End;
Pal:=x
End;
n = 59. , 95. 59 95,
154. , 451. : 605.
: 605 + 506 = 1111. .
50 80 , , .
Program Pr12_2;
Const a=50;b=80;
Function Pal(n:LongInt):LongInt;
Begin

End;
{******** *******}
Var n,t:LongInt; cnt,i:Integer;
Begin
For i:=a To b Do
Begin cnt:=0;n:=i;
While Pal(n)<>n Do
Begin t:=Pal(n); n:=n+t; Write(t,' ',n,' '); Inc(cnt) End;
WriteLn(i,' ',cnt)
End
End.
89. 16- , LongInt.

74

3. , (. 8, ).
.
Function Nod(a,b:longint):longint;
Begin
Repeat if a>b then a:=a mod b else b:= b mod a; until (a=0) or (b=0);
Nod:=a+b
End;
4. . n , .
. - . , . .
, . : n = 4, : 6,
15, 3, 9.

15

1-

2-

3-

4-

5-

6-

7-

8-

, n . n , . .

1. x, y, z. max(x,y,z), min(x,y,z) max(x,y,z) + min(x,y,z),
max/min .
max( x, x + y ) + max( x, y + z )
, 2. x, y, z.
1 + max( x + yz ,1,15)
max/min .
3. N . ,
.
4. Z=(SignX + SignY)Sign(X+Y),
1, a > 0

Sign(a)= 0, a = 0
1, a < 0

75

5. () : ) ; ) ; ) N .
6. : ) ; ) ; ) N .
7. . : ) ; ) , ( )
8. . , : ) ; ) ; ) , .
6+6
13 + 13
21 + 21
,
9. x=
+
+
2
2
2
.
10. n . , :
a. ;
b. ;
c. ;
d.

76

11. n . , :
;
;
, .. , 2?
12. n . ,
8. :
Function Yes8 (x:LongInt) :Boolean;
.
13. - n k (k < n). n , k - .
n- , k . .
14. . n .
, .
. ,
. .
15. n t k , ,
. (: C(t + 1, k)). t k. , t = 3, k = 2
00101, 01001, 01010, 10001, 10010, 10100.

12. :
:
1. (. 1, . 69 84);
2. ;
3. : 1 k; 1 ; n n=a1+a2+ ... +ak , k,
a1, a2, .... ak>0;
4. .

. , ( ,
, ).
:
Procedure Rec(t:Integer);
Begin
< >;
If < > Then Rec(t+l);
< >;
End;
:
.
.
Function Factorial (n: Integer): Longint;
Begin
77

If n=l Then Factorial :=1


Else Factorial :=n* Factorial (n-1) ;

End;
5!. ?
, ,
a:=Factorial(5), 5!.

. . , 1.
( ). ,
!

( ). - .
,
, , . . . , . , , , .
,
, ,
. (
), , .
, ,
.
Procedure Generate; (* t - . *)
Begin
If t=n Then Exit
Else Begin < 1>; t:=t+1; Generate; t:=t-l; < >; End;
End;
, .
1. (. 1, . 76).
:
b = 0
a ,

a + b = (a + 1) + (b 1), b > 0
(a 1) + (b + 1), b < 0

Function Sum (,b: Integer): Integer;


Begin
78

End;

If b=0 Then Sum:=a


Else If b>0 Then Sum:=Sum( a+l, b-1)
Else Sum:=Sum( a-1, b+1 );

2. .
Procedure Rec (n: Integer );
Begin
If n>l Then Rec(n Div 2) ;
Wri te (n Mod 2);
End;

?
3. , (.
1, . 77-78). -. , n , m,
n. m 2 n.
:
m=n;
n m, m+1
n-1.
Function Simple (,: Integer): Boolean;
Begin If m=n Then Simple:=True
Else Simple: = (n Mod m <> 0) And Simple(m+1,n) ;
End;
- Simple(2,n), n - .
4. n1. , : 2 a-1 n<2 . :
n = 0
1,
a ( n) =
a (n div 2) + 1, n > 1

Function a( n: Integer): Integer;


Begin If n=l Then a:=l Else a:=a(n Div 2) +1 ; End;
5. :
Function Nod (a, b: Integer):Integer;
Begin
If (a=0) Or (b=0)
Then Nod:=a+b
Else If a>b Then Nod:=Nod (a-b,b) Else Nod:=Nod(a,b-a);
End;
6.
.
Procedure Max_Vect_A(n:Integer; Var x:Integer);
Begin
If n=l Then x:=A[l]
Else Begin Max_Vect_A(n-1,x); fA[n]>x Thenx:=A[n]; End;
End;
7. .
Function Pow(a,n:Integer):Integer;
79

gin
If n=0 Then Pow:=l
Else If n Mod 2=0 Then Pow:=Pow(a*a, n Div 2)
Else Pow:=Pow(a,n-l) *a;
End;
8. (
- 0) :
Procedure Solve;
Var n:Integer;
Begin
ReadLn (n); If n<>0 Then Solve; Write (n:5) ; End;
9. , 1 (1, 1, 2, 3, 5, 8, 13,21,...). n-
:
n = 1 n = 2
1,
( n) =
(n 1) + (n 2), n > 2

Function Fib(n:Integer):Integer;
Begin
If n<=2 Then Fib:=l Else Fib:=Fib(n-l)+Fib(n-2) ;
End;
10. n ()
. : (), (d) ().
a:=a+d.
Function Sa (n, a: Integer):Integer;
Begin If n>0 Then Sa:=a+Sa (n-l,a+d) Else Sa;=0; End;
. Else .
( , ).


1. k.
1 k. , =3, k=2.
kn. , n 1
k, . , . : 1 1 1, 1 1 2, 1 2 1, 1 2 2,
2 1 1, 2 1 2, 2 2 1, 2 2 2. () ? , 1 1 2 1 2 1. -
, (
), ,
. .
? . ,
80

k. , , . . 1.
, , .
. - .
Integer, - : Type
Vector = Array[l..n] Of 0..k; Integer.
1 k, ( ?).
.
{$R+}
Program Prl3_l;
Const n=3; k=2;
Type Vector =Array[l..n] Of 0. .k;
Procedure Print;
Var i:Integer;
Begin For i:=l To n Do Write (A[i] : 3) ; WriteLn; End;
Procedure Solve(t:Integer); Begin End;
{**************************************}
Var A:Vector;
Begin
FillChar(A,SizeOf(A),0){*0. *} ;
Solve (1);
End.
Solve - t? ( ). - Solve(t+l), t,
n, , -
, i, t.
Procedure Solve(t:Integer);
Var i:Integer;
Begin
If t>n Then Print Else For i:=l To k Do Begin A[t]:=i; Solve (t + 1) ; End;
End;
,
: 2 2 2, 2 2 1, 2 1 2, 2 1 1, 1 2 2, 121, 1 1 2, 1 1 1.
, k . .
i- i.
. , (k>n),
. t A[t-1]+1 k-(n-t). 81

, t=n, n , , k; t=n-l,
-1 k-1 . . Solve.
Procedure Solve(t:Integer);
Var i:Integer;
Begin
If t>n Then Print
Else For i:=A[t-l]+l To k-n+t Do Begin A[t]:=i; Solve (t+1); End;
End;
.
Solve(l) Vector =rr[1..n] Of
l..k; Error 201: Range check error, For
i;=A[t-lJ+l To k-n+t Do. -
. Type Vector=Array[0..n] Of l..k;. , . Solve
A[t-l], . . 1
. [0]:=0; Solve(l); - Error 76: Constant out of range ( ). - Type Vector=Array[0..n] Of O..k;
, , .
2. 1 , .
1 n. ? . .
. n 3.
: 1 2 3, 1 3 2, 2 1 3, 2 3 1, 3 2 1, 3 1 2. , n=4. 1234,1243,1324,1342,1432,1423, 2134, 2143, 2314, 2341,, 4123.
, t
t+1
i+1.
Program Prl3_2;
{ Print }
Const n=4;
Type Vector =Array[1..n] Of Integer;
Procedure Swap (Var a,b:Integer);
Var :Integer;
Begin :=a; a:=b;b:=c; End;
Procedure Solve(t:Integer) ;
Var i:Integer;
82

Begin
If t>=n Then Print
Else For i:=t+l To n Do Begin Swap(A[t+l] ,A[i]) ; Solve(t+1);
Swap(A[t+l] ,A[i]) ;
End;
End;
{********************}
Var A:Vector,: i:Integer;
Begin
For i:=l To n Do A[i]:=I {* 1 2 3 ...n. *}
Solve(0);
{* . *}
End.
,
. , . Solve
=3? t=2? A[j]A[j]7 (
) Solve ( =3). .

:
Vector=Array[l..n] Of l..n; ( ).
(Error 26: Type mismatch) Swap. . , .
3. n. n
n=a1+a2+ ... +ak, k, a1, 2, ..., ak>0.
,
. 1, 2, ..., ak, 1 >2 > ... >ak. n=4
1+1+1+1, 2+1+1, 2+2, 3+1, 4 . ,
, .
4, 3+1, 2+2, 2+1+1, 1+1+1+1 . -
83

.
. t t . a1+a2+...+at=s,
t+1 ns,
( )
A[t+l]A[t]. t ,
, 1.
. .
. t
. Print
.
Procedure Print(t:Integer);
Var i:Integer;
Begin For i:=l To t Do Write (A[i] :3) ; WriteLn; End;
Solve : t, . , t, ... t -1, -2 ..., 1,
t+1 1, 2, ..., -1 .
.
{$R+}
Program Pr3_3;
Const =4 ;
Type Vector=Array[1..n] Of Integer;
Var A:Vector,:
Procedure Solve(n,t:Integer);
Var i:Integer;
Begin
If n=l Then Begin A[t]:=1; Print(t); End
Else Begin A[t]:=n; Print (t);
For i:=l To n-1 Do Begin A[t] :=n-i; Solve(i,t+1); End;
End;
End; {***************************}
Begin
Solve(n,l); ReadLn;
End .
, : 4, 3 1, 2 2, 2 1 1, 1 3, 1 2 1, 1 1 2, 1 1 1 1. 5,
6, 7 . .
Procedure Solve (n, t -.Integer) ;
Var I:.Integer;
Begin If n=l Then Begin A[t]:=1;Print (t);End
Else Begin If n<=A[t-l] Then Begin A[t]:=n; Print (t) End;
For i:=l To n-1 Do Begin A[t]:=n-i; Solve(i,t+l); End;
End;
End;
84

t-1 Type
Vector =Array[0..n] Of Integer; [0]:=
Solve (n,1). Error 201: Range check error. ?
, !
. : 4, 3 1, 2 2, 2 1 1, 1 2 1, 1 1 1 1. .
Procedure Solve(n,t:Integer);
Var i,q:Integer;
Begin
If n=l Then Begin A[t]:=1;Print(t)End
Else Begin If n<=A[t-l] Then Begin A[t] :=n;Print (t) End;
q:=Min (n-l,A[t-l]);
For i:=q DownTo 1 Do Begin A[t]:=i; Solve (n-i, t+1) ; End;
End;
End;
Min, , .
Function Min (a,b:Integer):Integer;
Begin If a<b Then Min:=a Else Min:=b; End;
: 4, 3 1, 2 2, 2 1 1, 1 1 1 1,
- . . :
1 1 1 1, 2 1 1, 2 2, 3 1, 4;
1 1 1 1, 1 1 2, 1 3, 2 2, 4;
4, 2 2, 1 3, 1 1 2, 1 1 1 1.
.
.


1. :
1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 (16 )
2 22222222222
(12 )
333333333
(8 )
4444
(4 )
333333333
(8 )
2 22222222222
(12 )
1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 (16 )
2. XIX .
3 , .
(1) (3), , , .
, ,
,
64 .
85

, , . , 64
, 58 . .


. . .
Program Prl3_zl;
Procedure MoveTown(High,FromI ,ToI ,WorkI: Integer);
Begin
If High>0
Then Begin MoveTown (High-1,FromI,WorkI, Tol) ;
Writeln( ,High, ,FromI, ,ToI) ;
MoveTown(High-1,WorkI,Tol,FromI) ;
End;
End; {***********************}
Var n: Integer;
Begin Write( = ); ReadLn (n); MoveTown(n,l,3,2) ; End.
3. n m, .
m + 1, n = 0

A(n, m) = A(n 1,1), n 0, m = 0


A(n 1, A(n, m 1)), n > 0, m > 0

n m,
.
4. F(n) :
1, n = 1

F ( n) = n
F (n div i ), n 2
i =2
?
Function F(n:Integer):Integer;
Var i,s:Integer;
Begin
If n=l Then s:=l Else For i:=2 To n Do s:=s+F(n Div 2) ;
F:=s;
End;
F n=5, 6, 7,
..., 20.
5. (,) (,)= =(-1,-1)+(1,), (,0)=1 (,)=1. . (
n ).
86

1. .
.
, ?
, , .

? ,
, , . . . , , , .
.
2. . . . . .
. ? . . : ,
. , , , , , , . ,
, , . . . (
), , . .
3. , . . , . . (1935 .), . . (1937 .), . .

14. :
:
1. c (. 1, . 23-25);
2. ;
3. c (. 2, . 25-29);
4. (. 2, 2728);
5. :
;
;
;
;
;
6. .

. Char. Char
, . .
Char . (ASCII - American Standard Code for Information Interchange) , ,
87

8-
.
0 127 ASCII. IBM- .
, 0 9 4810 (001100002) 5710
(001110012);
Z - 6510 (010000012) 9010
(010110102);
z - 9710 (011000012) 12210 (011110102);
- 12810 (100000002) 15910
(100111112).
, : '*' '3' 'G'.
: Ord Chr. Ord(w)
w, Chr(i) i. Ord
Chr : Chr(Ord(w))=w Ord(Chr(i))=i.
. , ASCII. Char Pred Succ : Pred(q)=Chr(Ord(q )-l) Succ(a)=Chr(Ord(a)+l).

1. . k
5 .
Program pr14_1;
Var ifk:Integer;
Begin k:=0 ;
WriteLn(' () - i .');
For i:=l To 255 Do Begin Write (i:4,' ',Chr(i)); Inc(k);
If k=5 Then Begin WriteLn; k:=0; End;
End;
End.
2. , For.
:

.
WWW...WWW (23 )
Program Pr14_2;
Var i :Char; j: Integer;
Begin
For i: = 'A' To 'W' Do
Begin For j:=l To Ord(i)-Ord('A')+l Do Write (i); WriteLn; End;
End.
,
.
Program Pr14_2m;
Var i,j:Char;
88

Begin
For i:='a' To 'z' Do For j:='a' To i Do Write (j);
ReadLn;
End.
3. , . '.' , Enter.
. Enter
? , . .
Enter () ( 13) ( 10).
Program pr14_3;
Var i:Char; j:Integer;
Begin
Read (i) ; j :=0;
While i<>'.' Do Begin Inc (j); Read(i) End;
WriteLn(j) ;
End.

. # , ASCII .
Program Pr14_3m;
Var i:Char; j:.Integer;
Begin
Read(i) ; j:=0;
While i<>#13 Do Begin Inc (j) ;Read (i) ;End;
WriteLn (j) ;
ReadLn;
End.
While i<>#10 Do Begin Inc(j); Read(i);End;,
. .
4.
.
Program Prl 4_ 4;
Var ch:Char; k:Integer;
Begin
Read (ch); k:=0;
While ch<>#13 Do
Begin IF (ch>=0 ) And (ch<='9') Then Inc(k);
Read(ch) ;
End;
WriteLn(' ' ,k) ;
End.
,
,
;
.
Upcase(ch) ch
, ,
, ch .
,
.
Program Prl4_4m;
Var ch:Char;
89

Begin
Read(ch) ;
While ch<>#13 Do
Begin IF (ch>='a) And (ch<='z') Then Write (Upcase (ch))
Else Write(ch);
Read (ch);
End;
End.
.
. - String. String: Var Strl: String[10]; Str2: String;
Str3:String[13].
() . , 255
. ,
-
(Strl[i] - i- Strl).
( 0) . String Write WriteLn ReadLn Read. To
, , . .
Program Prl4_5;
Var s:String; w:String[10]; v:String[5]; i,j:Integer;
Begin
ReadLn(v); WriteLn (v); WriteLn(Integer(v[0]));
ReadLn (w); WriteLn(w); WriteLn(Ord(w[0]));
ReadLn(s); WriteLn (s); WriteLn (Integer (s[0]));
For i:=l To Ord(s[0]) Do
Begin For j:=1 To i-1 Do Write (' ') ;
WriteLn (s [i]) ;
End;
ReadLn;
End.
v w , . , .
WriteLn(Integer(v[OJ)) WriteLn(Ord(w[0]))
. WriteLn(v[0]),
.

Integer(v[0]). - s:Array[0..255] Of
Char;. s .
: ,
, .
,
.
1. ( q) ( st).
Function QChar(q:Char;st: String): Byte;
Var i, k: Byte;
Begin
k:=0; For i:=l To Length (st) Do If st[i]=q Then Inc(k) ; QChar:=k;
End;
2.
.
Procedure MiDel( Var st: String);
Var k: Byte;
Begin
90

k:=Length (st);
If k Mod 2=1 Then Delete (st, k Div 2+1,1) Else Delete (st,k Div 2,2) ;

End;
3. w st V.
Procedure Ins (w,v:String;Var st: String);
Var k: Byte;
Begin
While Pos(w,st)<>0 Do
Begin k: = Pos(w,st) ;Delete (st,k,Length (w)); Insert(v,st,k); End;
End;
4. , .
Function Sum(st: String): Integer;
Var I, k, d, s: Integer;
Begin s:=0;
For i:=l To Length (st) Do Begin Val (st[i],d,k) ; If k=0 Then s:=s+d; End;
Sum:=s;
End;

1. . . ,
, . , . . .
, .
Program Pr14_;
Const n=20, m=l0; ( *
. , . *)
Type TString=String[m];
Procedure DelPr(Var s:String); { . }
Begin While (s[l] = ' ') And (s<>") Do Delete (s,l ,1) ; End;
Function GetWord(Var s:String) :TString,{ , , . }
Begin GetWord:=Copy (s, l, Pos(' ' ,s)-l) ; Delete(s,1,Pos (' ',s)); DelPr (s) ; End;
{*****************************************************}
Var A:Array[1..n] Of TString; s: String; k, I:.Integer;
Begin
WriteLn(' '); ReadLn (s);
s:=s+' ';{ . ? }
DelPr(s);{ . }
k:=0;
{ .}
While s<>'' Do
gin Inc(k) ;A[k]:=GetWord (s);{ . } End;
For i:=l To k Do WriteLn(A[i]);
ReadLn;
End.
DelPr(s) ,
GetWord . ? ?
91

, ? DelPr While (s[l]=' ') And (s<>") Do Delete(s,l,l) While (s[l]='


') Do Delete(s,l,l). ,
. .
2. .
.
Program Pr14_7;
Var i : Integer; s: String;
Begin
WriteLn (' '); ReadLn (s) ;
I:=1;
While i<Length (s) Do
Begin If (s[i] = ',) And Not (s [i+l]=' ')
Then Insert( ,s,I+1);
Inc (i) ;
end;
WriteLn (s) ;
End.
While, For? Pos(' ',s)? ,
, . '!', '?', '.' ,
. .
3. X Y. (r) X
, X Y . : X='abcd',
Y='dxxc, r=4; ='1111111, Y='111222',r=7. .
Program Pr14_8; Var i , j , r : Integer ; S, X, Y :String;
Begin
WriteLn (' ' ) ; ReadLn (X) ;
WriteLn (' ' ) ; ReadLn (Y) ;
If Length(X)>Length(Y)
Then Begin S:=X; X:=Y; Y:=S; End;{*Y .*}
r:=Length(Y) ;
For i:=l To Length (X) Do
Begin While (j<=Length(Y) ) And (Y[j]<>X[i]> Do Inc(j) ;
If j>Length(Y) Then Inc(r)
Else Begin Dec(r); Delete(Y,j,1);End;{*
. Y. *}
End;
WriteLn (' ' , ) ;
End.

Y ? .
Delete(Y,j,l). ?
, , () .
4. .
(), .
2"-1, n . , . , , 010101 'bdf
'abcdefh'. :
, 1 0, 110011 001011. 0000001.
92

Program Pr14_9;
Const MaxN=6;
Type Vector=Array[l. .MaxN+1] Of Byte;
Function Eg(X,Y:vector ;n:Integer): Boolean; {*
0000001, n=6. *}
Var i :.Integer;
Begin
i : =1 ; While (i<=n) And (X[i]=Y[i]) Do Inc(i);
Eq:=(i>n) ;
End;
{***********************************}
Var A,Last:vector; i:Integer; s:String;
Begin
WriteLn ( ' ' ) ;ReadLn (s) ;
FillChar(A,SizeOf(A) ,0) ;
FillChar (Last, SizeOf (Last) ,0) ;
Last [Length (s) +1] :=1 ; { * . *}
{ , .}
While Not (Eq(A, Last, (Length (s) +1) ) ) Do
Begin
i : =1 ;
While (i<=Length (s)) And (A[i]=l) Do Begin A[i]:=0;Inc (i) ;End;
A[I]:=1;
If I<=Length (s)
Then For i:=l To Length (s) Do
If A [I]=1 Then Write (S[i] ) ; (* . *}
WriteLn;
End;
ReadLn;
End.

, : 000000, 100000, 010000,
110000, 001000 . . . , : 000000, 000001, 000010, 000011, 000100 . . ?

1. :
ZYYXXXAA..AA;
ABCZZBCZZZCZZ..ZZ.
2. , True, ,
, False .
3. , (. .
, ).
4. .
5. . ,
.
6. . , .
7. . , .
8 . . :
;
, ;
93

, ;
, ;
, .
9 . . , .
1 0 . . .
1 1 . . , :
;
.
12. . , :
;
;
(a, ab, abc, abcd,...).
13. . , :
.
14. .
, , , , . .
15. . , .
16. . , ,
.

15. :
:
1. (. 1, . 27-29);
2. ;
3. :
f(x)=0;
;

;
4. .

.
( ), ( , ). : Real, Single, Double, Extended, mp ( Real).

, Longlnt 19 .
: '+' , '-' , '*' , '/' .
, '=' .

, 127.3, 25.0, -16.003, 200.59, 0.54
12 , 0.000009 9-6, 0.62*10 4
0.62+4, -10.8*10 - -10.812
94

. . .
Program pr15_1;
Var x,y:Real;
Begin
:=0.3;:=0.3; WriteLn(x=y) ;
ReadLn; End.
True.
:Single. 1 , Error 116: Must be in 8087 mode to compile this. ,

-, .
.
.
{$N+}.

. {$N-}, ,
6- , . . Real. {$N+} ,
.
,
{$N+} . . :
{$N+}
Program prl5_lm;
Var x:Real; :Single;
Begin
x:=0.3;y:=0.3;WriteLn (x=y); WriteLn(x); WriteLn (y); ReadLn;
End.
False. .
. {$N+} Write Extended, , , .

(sin(30)=sin(0.5236...)=0.5) .
Const b. , WriteLn(Pi)
WriteLn(Pi:a:b). a,
b Pi .
{$N-}
Program pr15_2;
Begin
WriteLn (Sin (0. 5236) ) ;
WriteLn (Pi);
End.
{$N+}
Program prl5_2;
Begin
WriteLn(Sin(0.5236));
WriteLn(Pi) ;
End.
. , (/)*=.
{$N+}
Program pr15_3;
95

Var x:Extended; i, cnt:Integer;


Begin
cnt:=0;
For i:=20000 To 30000 Do
Begin x:=i/10000; x:=x*10000; If x=i Then Inc(cnt); End;
WriteLn(' ',cnt);
WriteLn (' ',10001-cnt);
ReadLn; End.
. 8209, 1792. i . ,
, . . ,
.
. , ,
,
. .
($N+)
Program pr15_3;
Const eps=l.0-10;
Var :Extended; i,cnt:Integer;
Function Eq(x ,y:Real):Boolean;
Begin
Eq:=Abs(x-y)<eps;
End;
Begin
cnt:=0;
For I:=20000 To 30000 Do
Begin x:=1/10000; x:=x*10000; If Eq(x,i) Then inc(cnt);End;
WriteLnC ' ' ,cnt) ;
WriteLn(' ',10001-cnt);
ReadLn;
End.
10001 .

1. f(x)=0, f(x) . *, f(x*)=0. [,b], f(a)<0, a f(b)>0. , .

, .
[,b]. f(c)>0, b , f(c)<0, . , .

f(x)=x2-2, . . 2.
.
{$N+}
Program pr15_5;
96

Const eps=1.0E-3;
Function Eq(x,y:Real):Boolean; {* . *}
Function F (x:Real):Real;
Begin
F:=Sqr(x)-2;
End;
{***************************}
Var a,b,c:Real;
Begin WriteLn(' a<b ') ;
ReadLn (a,b);
If F(a)*F(b)>0
Then WriteLn('Ha . ')
Else Begin While Not Eq(a,b) Do
Begin c:=(a+b)/2; If F(c)>0 Then b:=c Else
a:=c; End;
WriteLn(' ', a) ;
End;
ReadLn;
End.
, f(x)
. . b . 1.4140625 1.41357421875 ( ), 1.414213...
eps 1.0-6. Real. :
2-6+5=0
x-cos(x)=0
-ln()-2=0
2 3 -9 2 -60+1=0
, [,b], ? ,
(, ):
X
0
2
3
6
F(x)
+
, - , , , . . .
2. f(x) - [,b] (<b).
, f(x),
= -b. [,b] x=(b-a)/n: a=x(0)<x(l)<...<x(i)<x(i+l)<
<()=b. [x(i),x(i+l)} ,
f(x(i)).
.
. : S = (b-a)/n*
(f(x(0)+f(x(1))+...+f(x(n-1)). , , .
, .
?

97

f(x)=x2
1 2. 2.333...
{$N+;}
Program pr15__6;
Const eps=1.0E-3;
Var a,b, s ,dx:Real;i ,n : Integer ;
Function Eq(x,y:Real) : Boo lean; {* . *}
Function F ( : Real) : Real ;
Begin F:=Sqr(x); End;
Begin
WriteLn (' , ');
ReadLn (a,b,n) ;
x:=a; dx:= (b-a) /n; s:=0;
For i:=l To n-1 Do Begin s:=s+F(x); x:=x+dx; End;
WriteLn (' ' , (b-a)/n*s) ;
ReadLn;
End.

. . =6 1.5277..., n=50
2.224992..., n=100 - 2.78749..., n=300 - 2.315046... .
n. ,
n . n 10, 100. ,
, .
. . , .
Program pr_6m; _
Const eps=1.0E-3; nb=10;ns=100;
Var a,b, wn, ws :Real ; i, n :.Integer;
Function Eq (x, : Real) : Boolean; {* . *}
Function F(x:Real) :Real;
Function Sq (n: Integer):Real;
Var x,dx,s:Real;
Begin
X : = a; dx : = (b-a) /n ; s : = 0 ;
For i:=l To n-1 Do Begin s:=s+F(x); x:=x+dx; End;
Sq:= (b-a) /n*s;
End;
Begin
WriteLn (' ' ) ; ReadLn (a,b) ;
n :=nb ; wn : =Sq (n) ;
Repeat
ws : =wn; n : =n +n s ; wn : =Sq (n) ;
Until Eq(ws, wn);
WriteLn (' : ' , n , wn ) ;
ReadLn;
End.
, =810
, 2.32654955.... .
98

1.0-6.
, =23310 2.33309739...
: f(x)=l/(l+-a), [0,1];
f(x)=l/x, [1,3]; f(x)=8in(x), [0,Pi/2].
3. .
,
:
x2 x3
xn
+
+ ... +
+ ...
2! 3!
n!
x3 x5 x7
x 2 n +1
sin( x) = x
+

+ ... + ( 1) n
+ ...
3! 5! 7!
(2n + 1)!
ex = 1+ x +

2n
x2 x4 x6
n x
cos( x) = 1
+

+ ... + (1)
+ ...
2! 4! 6!
2n!
x2 x3 x4
xn
ln(1 + x) = x
+

+ ... + (1) n +1
+ ...
2
3
4
n

() 1 < x 1

, , , . . eps
. , eps eps ( ?). .
sin(x).
{$N+}
Program pr15_7; Const eps=1.0E-3;
Function Eq(x,y:Real):Boolean;{* .*}
Function F(n:Integer;Var x:Real):Real;
Var i:Integer; s:Longlnt;
Begin s:=1;
For i:=2 To n Do s:=s*i;
x: =x *Sqr (x) ; F:=x/s;
End;
{******************************************}
Var x, sn, ss: Real; p, n: Integer;
Begin
WriteLn (' '); ReadLn(x) ;
ss : =0 ; sn : = ; n : =1 ;
: =1 ; { * - . *}
Repeat
ss:=sn; { * .*}
n:=n+2;p:= -l*p; sn :=ss+p*F (n,x) ;{* . *}
Until Eq(ssfsn) Or (n>=12) ; { *

.*}
WriteLn (' ' ,sn); ReadLn;
End.
, sin(30)=1/2,
sin(45) = Sqrt(2)/2, 30=0,5236... ,
45=0,7854... . .

.
, . .

99

1. :
1
1
1
Y = (1 )(1 )...(1 ), n > 2
2
3
n
Y = Cos (1 + Cos (2 + ... + Cos (39 + Cos 40)...))
Y = Sinx + SinSinx + ... + SinSinSin...Sinx ( n
Y = Sinx + Sinx + ... + Sinx
2

Y = Sinx + Sin 2 x + ... + Sin n x


Y = x + x4
Y = x + 4x3 7x 2
Y = x 2 + 3x 8
3

Y = 6b 2 + b 3 15
Y = (3 x 3 + 18 x 2 ) * x + 12 x 2 5

2. :
1
1
1
+
+
+ ...
1* 2 2 * 3 3 * 4
1
1
1
+
+
+ ...
1* 3 2 * 4 3 * 5
1
1
1
+
+
+.
1* 2 * 3 2 * 3 * 4 3 * 4 * 5

100

16. : . .

1. ;
2. :
, (. 2, 14-15);
;

;
;
;
3. .

, ,
.
.

.
.

? :
.
.
, . ( Integer - 2 ). 5, - 4. [1,1] 1000. [4,3]. Addr(A[4,3])=1000+2*(4*(4-1)+(31))=1028. ? 4 .
12 , 4- 3- 2 .
2, 2
.
A[N,M] , V
, :
Addr(A[i,j])=Addr(A[1,1 ])+V*(M*(i-l)+(j-l)).
-.
:
Const MaxN=...; MaxM=...;
{*
.*}
Type Vect=Array[l..MaxM] Of integer;{* .*}
Matr=Array[l..MaxN] Of Vect; {* ,
.* }
Type Matr=Array[l..MaxN,l..MaxM] Of Integer; {*
.* }
, ( ) ,
65520 .

. , () , :
for i:=1 to m do
for j:=1 to n do a[i,j]:=random(10);
101

:
for i:=1 to m do
begin for j:=1 to n do write(a[i,j]:5);
writeln;
end;

1. . , .
2. .
Procedure Search (v,w:Integer; var X:matr; Var max,si max,sjma x:Integer) ;
Var i , j :Integer;
Begin smax:=X[1,1]; simax:=1; sjmax:=1;
For i:=1 To v Do
For j:=1 To w Do
If X[ i , j ]>smax
Then Begin smax:=X[i, j] ;
simax:=i; sjmax:=j;
End;
End;
3. ,
.
, ,
.
Const MaxN=10; =8;
Type Matr=Array[l..MaxN,1..MaxM] Of Integer;
Vect=Array[1..MaxN] Of Integer;
Var
A:Matr; Sum:Vect;
n,m:Integer;
Procedure SumNeg(v,w:Integer; Var X:Matr;Var Ssum:
Vect);
Var i,j;Integer;
Begin
For i:=l To v Do
Begin Ssum[i] :=0;
For j:=1 To w Do
If X[i,j]<0 Then Inc(Ssum[i],X[i,j]) ;
End;
End;
4. , , 0.
Function SNeg (v,w:Integer; Var X:Matr):Boolean;
Var i,j:Integer;pp:Boolean;
Begin
pp:=False;
For i:=1 To v Do
For j:-1 To w Do If X[i,j]=0 Then
pp:=True;
SNeg:=pp;
End;
5. , . 102

i=j, i=N-j+l, N
.
Function Sim (v,w:Integer; var X:Matr):Boolean;
Var i,j :Integer; pp:Boolean;
Begin pp:=True;
For i:=1 To v-1 Do
For j:=i+l To w Do If X[i,j]<>X[j,i] Then pp:=False;
Sim:=pp;
End;
, .
6. *
.
Procedure Change( v,w:Integer;Var X:Matr);
Var i,j: Integer;
Begin
For i:=l To v Do
For j :=1 to w Div 2 Do Inc (X[i,2*j] ,X[i, 1]) ;
End;

, . , . X[i,2*j-1] , 3, 5 . .
.
Change.

1. . :
k1 k2;
A ;
;
.
2. . :
kl no k2;

;
();
();
, () ;
.
3. . , ( ).
4. . :
; ;
A ;
5. . , ():
;
;
, ;
103

, .
6. . :
;
;
,
;
I ;
k1 k2.

17. : . .

1. ;
2. .


1. t.
:
t ;
t- ;
t+1 .
ReadLn(n,m,t). :
Procedure InsertStr(v,w,r:Integer;Var X:Matr);
Var i , j :Integer;
Begin
For i:=v DownTo r+1 Do
For j:=l To w Do X[i+1, j] : =X[i , j] ;
For j:=l To w Do X[r+l,j]:=0;
End;
.
2. ,
. (
).
{$R+}
Program Pr17_2; Const MaxN=8; MaxM=9;
Type Matr = array[1..2*MaxN,l..MaxM] Of Integer;
{ * 2MaxN ,
. *}
Procedure vvod2(v,w:Integer;Var X:matr);
Var i,j:Integer;
Begin
For i:=1 To v Do
104

For j:=l To w Do Readln (X[i, j]) ;


End;
Procedure vivod2(v,w:Integer;X:matr);
Var i,j:Integer;
Begin
For i:=l To v Do
Begin
For j:=l To w Do Write (X[i, j] :4) ;
WriteLn;
End;
End;
Procedure InsertStr(v,w,r:Integer;Var X:Matr);
Var i,j:Integer;
Begin For i:=v DownTo r+1 do
For j:=l To w Do X[i+l,j] :=X[i,j] ;
For j:=l To w Do X[r+l,j] :=0;
End;
(* . *}
Function TMax(v,w:Integer;X:Matr):Integer;
Var i,j,max:Integer;
Begin
max:=X[1, 1 ] ;
For i:=1 To v Do
For j:=l To w Do If X[i,j]>max Then max:=X[i,j];
TMax:=max
End;
Procedure Solve(Var v:Integer;w:Integer;Var X:Matr);
Var i,j,smax:Integer;
Begin
smax: =TMax (v, w, X) ; { * . *}
i:=l;
While i<=v Do {* ?*}
Begin j:=1;
While (j<=w) And (X[i,j]<>smax) Do Inc(j);
If j<>w+l
Then Begin{*B . *}
InsertStr(v,w,i,X);{* .*}
V:=v+1;{* . *}
i:=i+2; {* . *}
End
Else I:=I+1 ;{* . *}
End;
End;
{ * - . *}
105

Var A:matr; n,m:Integer;


Begin
Readln(n,m); vvod2(n,m,A); vivod2(n,m,a);
Solve(n,m,A); vivod2(n,m,A);
End.
, , .
3. t.
, t, , , . ,
.
Procedure DelStr(v,w,r:Integer;Var X:Matr);
Var i,j:Integer;
Begin
For i:=r To v-1 Do
For j:=l To w Do X[i,j] :=X[i+1 ,j] ;
For j:=l To w Do X[v,j]:=0;
End;
4. , .
Procedure Solve(Var v:Integer;w:Integer;Var X:Matr);
Var i,j,smax:Integer;
Begin
smax: =TMax (v, w, X) ;
i:=l;
While i<=v Do
Begin j:=1;
While (j<=w) And (X[i,j]<>smax) Do j:=j+1;
If j<>w+l Then Begin DelStr (v,w,i,X) ; v:=v-1 ; End
Else I:=I+1;
End;
End;
Solve,
, .
4. 11 12.
Swap . .
Procedure Swap (Var x, : Integer);
Var z: Integer;
Begin z:=x; x:=y; y:=z; End;
, ,
.
Procedure Change(v,stl,st2:Integer; Var X:Matr);
Var i:Integer;
Begin For i;=1 To v Do Swap(X[i,stl] ,X[i,st2]) ; End;
106

.

5. , .
.
2 7 9 3 4
5 6 9 0 1
2 1 9 5 8
7 6 9 4 3
5 6 9 2 1
9. , , .
, .
, .
NumStr NumStl .
: (1, 2, 3, 4, 5) (3, 3, 3, 3, 3). ,
, . . 3. . ,
, . () NumStr , .
Solve,
.
Procedure Solve(Var v,w:Integer;Var X:Matr);
Type vector=Array[1..MaxN] Of Integer;
{*
. MaxN , . *}
{*
. *}
Procedure FNum(Var q,r:Integer;Var Y,Z:vector);
Var i,j:Integer;
Begin g:=0;r;=0;
For i:=1 To v Do
For j:= 1 To w Do If X[i,j]=smax
Then Begin Inc(q) ;Y[q] :=i;
Inc(r) ;Z[r] :=j ;
End;
End;
{* .*}
Procedure Sz(Var t:Integer; Var X:vector);
Var i,j,l:Integer;
107

Begin
i:=l;
While i<t Do
Begin
j:=j+l;
While j<=t Do
If X[i]=X[j]
Then Begin For l:=j To t-1Do X[l] :=X[1+1];
X[t]:=0; Dec (t) ;
End
Else Inc (j) ; Inc(i) ;
End;
End;
{* , .*}
Procedure Change (t,a:Integer;Var X:OMyArray);
Var I:.Integer;
Begin For i:=2 To t Do If X[i]>a Then Dec(X[i]);
End;
{* .*} {* .*}
Var i,smax:Integer;
NumStr, NumSt1:vector;{*
. *}
ykStr,ykStl:Integer;{*
NumStr NumStl. *}
Begin
FillChar(NumStr,SizeOf(NumStr),0);{* . *}
FillChar(NumStl,SizeOf(NumStl),0);
smax: =TMax (v, w, X) ; { * - . *} FNum(ykStr,ykStl,NumStr,NumStl);{*
. *}
Sz (ykStr,NumStr);{* . *}
Sz (ykStl,NumStl);
i:=l;
While i<=ykStr Do
Begin
DelStr(v,w,NumStr[i],X);{* . *}
Change (ykStr,NumStr[i],NumStr);{* . *}
Dec(v); Inc(i);End;
i:=l; While i<=ykStl Do Begin DelStl(v,w,NumStl[i],X);{* . *}
Change(ykStl,NumStl[i],NumStl) ; {*
.*} Dec(w); Inc(i) ; End; End;
108

. ,
Solve
. ,
. Solve
( i). , .


1.
, ;
, ;
,
;
, ;
, ;
, 0,
, ;
;
;
,
2.
, ;
h I;
, ;
, ;
();
, ;
, ;
, .
3.
;
;
.
4.
;
;
;
;
;
;
;
, ;
;
, ;
, :
, , ..., , ;
, , , , ,...
5. , .
109

6. . .
7. N*N, N . , , .
8. (N*N)
, .
9. (N*N) , .
10. . , .
.
11. A[i,j] ,
i /. .
12. k, k k .
13. ,
.
14. A[i,j] , . A[k,l] {i-l< k< i+1), (J-l< I <j+l), (k,l)* (i,j). . .
15. X A[1..N,1..M] (
) , 0(N+M).

18. :
:
1. , ;
2. : ,
n, , ;
3. .


1. n. ,
n ( ).
Program Pr18_1;
Type Mn=Set Of 0. . 9 ;
Var s:Mn; n:LongI nt; i : I n t e g e r ;
Begin
WriteLn(' ' ) ; ReadLn (n);
s:=[0..9];
While n<>0 Do
Begin
S:=s- [n Mod 10] ;{* . *}
n:=n div10;
End;
For i:=0 To 9 Do If i In s Then Write (i:2) ;
WriteLn; ReadLn;
End.
,
.
2. . 2 n.
110

.

, ,
, . .
Program Pr18_2;
Const n=1000;
{* , .
*}
Var i:Integer;
Function Simple (m:integer):Boolean;
Var i:Integer;
Begin i:=2;
While (i<= m Div 2) And (m Mod i<>0) Do Inc(i) ;
Simple: = (i>m Div 2);
End;
Begin
For i:=2 To n Do If Simple (i) Then Write ( i , ' ' : 3 ) ;
ReadLn;
End.
, 1000
.
. , .
, , .
?
, , , .

.
Program Pr18_2m;
Const n=255;
Type Mn=Set Of 0..n;
Var Sim:Mn; i , j : I n t e g e r ;
Begin
Sim:=[2.. n ] ; j:=2;
While j<=n Div 2 Do
Begin If j In Sim
Then Begin {*
*}
i: = j +j:
While i<=n Do
Begin Sim:=Sim-[i];
I:=I+j;
End; {**}
End; j:=j+1;
End;
For i:=2 To n Do If i In Sim Then Write (i: 4) ; {* , . *}
End.
, , 0.. 255, 256 . ,
. , , :
{$R+}
Program Pr18_2mm;
Var Mn: Set Of 1..255;
111

.

a:.Word;
Begin
Mn:=[l..255]; a:=258;
If a In Mn Then WriteLn (' Yes') Else WriteLn ('No') ;
End.
Error 202: Range check error. .
.
{$R+}
Program Pr18_2mmm;
Const m=255; n=1000;
Type Mn=Set Of 1..m;
Vector=Array[0..(n Div m)] Of Mn;
Var Sim:Mn; A:vector; i, j, k :I n t e g e r;
Begin
k:=(n Div m) ;For i:=0 To k Do A[i]:=[1. .m];
j:=2;
While j<=n Div 2 Do
Begin
If (j Mod m) In A[j Div m]
Then Begin
i:=j+j;
While i<=n Do
Begin
A[i Div m] :=A[i Div m]-[i Mod m];
Inc(i,j);
End;
End;
Inc(j) ;
end;
For i:=2 To n Do If (i Mod m) In A[i Div m]
Then Write ( i , ' ' : 3 ) ;
End.

1. . , :
'0' '9' ;
'' 'F' 'X' 'Z';
'E' N.
2. , ... Z, .
3. . , .
.
4. . .
5. . , :
( ) ;
;
.

112

19. :
:
1. ( Pascal. I. . 2, . 37-45; 50-52);
2. ;
3. ;
4. :
;
;
;
5. .


. . . : #13 #10 ( , ), .
, , , , , . .
.
( ) Input Output,
Dos Con (). , Read
Write ,
.
. ,
, a Input Output
.
:
Var f:Text; s:String;
Begin Assign(f,'a:\data.txt'); { data.txt
}
Reset(f);{ .}
ReadLn(f,s);{ .}
Close(f);
End.
ReadLn ,
. , , .
, ,
10- , . , . . 100- ,
10-. , .
, , ,
- . ? Eof (
>), True, ,
False .
.
1. () .
113

.

Program pr19_1;
Var f:Text; s:String;
Begin Assign (f, 'Input.txt'); Reset(f);
While Not Eof (f) Do Begin ReadLn (f,s); WriteLn
(s); End;
Close (f);
End.
Error 2: File not found. Input.Txt , . ,

Dddd

Ffffff
Ggggggg
Input.txt. , .
Input.txt
(). File/Change Dir . . Error 2:
File not found. , Input.Txt
. Input.Txt , . . .
. ReadLn(f,s) Read(f,s). . Ctrl+Break, ,
. .
Debug/Watch, s . ,
. .
? .
Program pr19_1m;
Var f:Text; ch:Char;
Begin
Assign(f,'Input.Txt');
Reset (f);
While Not Eof(f) Do Begin Read(f,ch); Write (ch);
End;
Close(f);
End.
. Read(f,ch); Write(ch);
Read(f,s); Write(s); s String, . . ,
.
. :
Program pr19_1mm;
Var f:Text; ch:Char;
Begin
Assign(Input,'Input.Txt'); Reset (Input);
While Not Eof Do Begin Read(ch) ; Write (ch); End;
Close (Input);
End.
. ?

. Read Write. Close(Input) ReadLn(s); WriteLn(s), s .
114

.

Error 104: File not open for input ( ). Close(Input) Reset(Input).
. s
1put.Txt. ?
. .
Program pr19_2; Uses Crt;
Const MaxN=100;
Type Vector=Array[l..MaxN] Of Integer;
Var A:Vector; i,j:Integer;
Begin
ClrScr;
Assign(Input,'Input.Txt') ; Reset (Input);
i:=0; While Not Eof Do Begin Inc (i) ; Read (A[i] ) ; End;
Close (Input);
For j:=l To i Do Write (A[j] :2) ;
End.
Error 106: Invalid numeric format ( ). ,
, . Input.Txt
I
22
333
4444
55555
. .
Input.Txt.
1
2 22
3 3 333
4 4 4 4444
5 5 5 5 55555
. , , 55555.
-9981. ,
. , {$R+} . .
Program pr19_2m; Uses Crt;
Const MaxN=100;
Type vector=Array[1..MaxN] Of Integer;
Var A:Vector; i,j,k:Integer; ch:Char;
Begin
ClrScr; Assign (Input, 'Input. Txt'); Reset (Input);
i :=0;
While Not Eof Do
Begin Read (ch);
{ Val (ch, j, k); }
{If k=0 Then Begin} Inc(i) ; A[i] :=0rd(ch)0rd('0') ; {End;}
End;
Close (Input);
For j:=l To i Do Write (A[j] : 6) ;
End.
: 1 -35 -38 2 -16 2 2 -35 -38
3, . . . : 1 2 2 2 3 3 3 3
3... , 1 2 22 3 3 333 ..... .
115

.

? Pr16_2
Type Vector=Array[l..MaxN] Of Real; , , Input.Txt.
.
.
Output.Txt. Pr16_3, Input.Txt, Output.Txt (
) , . Input.Txt, .
Program Pr19_3 ; Uses Crt;
Var ch:Char;
Begin ClrScr;
Assign(Input,'Input. Txt'); Reset (Input);
Assign(Output,'Output. Txt'); ReWrite(Output);
While Not Eof Do Begin Read (ch); Write(ch) End;
Close(Input); Close (Output);
End.
Close(Input); Close (Output); .
Assign(Input,'Con'); Assign(Output,'Con'); Reset (Input);
Rewrite(Output) ; ReadLn(s); WriteLn(s);
- ,
Enter.
.

1. , ,
-100 100. ,
.
. .
Program Pr19_4;
Const MaxN=10000; =100; b=200; =15;
Var i,j,k:Integer;
Begin Randomize;
Assign (Output,'Number.Txt') ; Rewrite(Output);
i:=0; k:=0;
While i<MaxN Do
Begin j:=Integer (Random(b))-a;
Inc(i) ;Inc(k) ;
Write (j); Write ( ) ;
If k=c Then Begin WriteLn; k:=0; End;
End;
Close (Output);
End.
. Number.Txt .
MaxN , .
100000 ? MaxN
. ,
i Longlnt.
.
? ,
{Write(' '); If k=c Then Begin WriteLn;k:=0;End;} .
,
,
( ). : Error. Line too long, truncated ( , 116

.

); , , : Warning. Error encountered reading file NUMBER.TXT (
). ,
,
.
.
Program Pr19_5;
Const MaxN=100; c=20;
Type Vector=Array[-MaxN..MaxN] Of Integer;
Var A:Vector; i,j:Integer;
Begin
FillChar(A,SizeOf(A),0); {,
. .
. , , .}
Assign(Input,'Number.Txt');
Reset (Input);
While Not Eof Do Begin Read (i) ;Inc (A[i] ) ;End;
Close (Input);
Assign(Output,'Count.Txt');{ Count.Txt, .}
Rewrite(Output);
For i := -MaxN To MaxN Do Write (A[i] ,' ') ; Close (Output);
Assign(Input,'Count.Txt');{ Count.Txt .}
Reset (Input);
Assign(Output,'Con');{ . }
Rewrite(Output);
j:=0; While Not Eof Do
Begin Read (i) ; Inc (j) ;
Write (i,' ');
If j=c Then Begin WriteLn; j:=0;End; { ,
.*} End;
End.
: :
; Number.Txt Count.Txt.
, , . :
. , 10000 . ?
, ASCII .
, . Number.Txt ,
.
, . , . . ? .
.
. , 10000 . ,
, ,
.
2. , .
(, ,
) .
:
117

.

6. (()) ;
7. {( ] } ;
8. ({[}]) .
. , ,
.
.
.
Program Pr19_sk;
Begin
Wri teLn ( { * 9 ( ( ( ) ) ) [ [ [ [ ] ] ] ] *}');
End.
, ( ASCII)
. .
Program Pr19_; Uses Crt;
Begin
ClrScr;
WriteLn ( Ord ( ( ) ) ; WriteLn (Ord ( ) ) ) ;
{: 40, 41.}
WriteLn (Ord ( [' ) ) ; WriteLn (Ord ( ] ) ) ; {: 91, 93.}
WriteLn (Ord({) ) ; WriteLn (Ord ( } ) ) ; {0: 123, 125}
ReadLn; End.
, 2. . , , .
.
Char , 100. , . , . 2,
, , .
{$R+}
Program Pr19_6;
Const MaxN=100;
Type Vector=Array[ 1..MaxN] Of Char;
Var A:Vector; ch:Char; yk: Integer ; ff:Boolean;
Begin
FillChar(A,SizeOf(A),0); yk:=0; ff:=True;
Assign (Input, 'Pr16_SK.PAS' ) ; Reset (Input);
While (Not Eof) And ff Do
Begin Read(ch) ;
If (ch=( ) Or (ch=[) Or (ch={)
Then Begin Inc(yk); A[yk]:=ch; End
Else If (ch=)) Or (ch=]) Or (ch=})
Then If Ord(ch)- Ord(A[yk])<=2 Then Dec (yk)
Else ff:=False;
End;
Close (Input);
If ff Then WriteLn ( ' ')
Else WriteLn ( '
');
End.
Pr19_sk. . , , ,
. , 118

.

Error 201: Range check error. . .
, , , WriteLn .
.
3. Pr19_7.PAS.
, , . , .
, ,
.
Program Pr19_7;
Const MaxN=100;
Type Vector=Array[1..MaxN] Of String;
Var A:Vector;
Cnt, i :Integer;
Begin
cnt:=0;
Assign (Input, 'Pr3_7. PAS'); Reset (Input);
While Not Eof Do Begin Inc(cnt); ReadLn (A[cnt] ) ; End;
Close (Input);
WriteLn(cnt);
For i:=l To cnt Do WriteLn (A[i]) ;
End.
, , .
. , . . .

1. , .
;
, ;
, ;
,
;
, ;
;
;
.
2. , .
, ;
, ;
;
().
3. . .
4. . ,
.
5. . : , , .
6. ( ).
. Rename .
7. , n . abcdefqwrt

119

3 , wrtabcdefq. To ,
.
8. . . , Begin End.
9. , 80 .
, :
, .
10. , . , (,
13.05.1949 .). .

20. : ()

1. ;
2. ;
3. .

. , .
.
,
. . . ,
, , .
:
< > = Record
< 1>:< 1>;
< 2>:< 2>;
..
< >:< >
End;
. . , .
, , .
Year=1583..3000;
Month_number=l..12;
Day=l.. 3 1 ;
D ate=Record
Dyear:Year;
Dmonth:Month_number;
Dday:day;
End;
, date :
Type date=Record
Dyear: 1583..3000;
Dmonth: 1..12;
Dday:1 ..31;
End;
, Year, Month_ number, Day.
,
, . : < >.< >.
120

.

. Var t:Date; -

t.dyear:=1987;
t.dmonth:=12;
t.dday:=30;
With: With < > Do <>;.
-.
With t Do Begin
dyear:=1987 ;
dmonth:=12 ;
dday:=30;
End;
Case () ,
( ), Else. ,
-32768 32767. Case , ,
, .
Else, , Else.
Else , .
:
Var :Char;
Begin
ReadLn ()
Case Of
' 0 ' . . ' 9 ' : WriteLn( ' - .');
''. . 'z': WriteLn (" . ' ) ;
''. . ' Z' :WriteLn ( ' . ') ;
Else WriteLn ( ' . ')
End;
End;
Var i:Integer;
Begin
ReadLn (i);
Case i Of
0 , 2 , 4 , 6 , 8 : WriteLn('i 1 0 . ' ) ;
1 , 3 , 5 , 7 , 9 : WriteLn ('i 1 0 . ' ) ;
End;
End;

1. . year, month_ number, day,
date, . .
(366 ),
4. , , 400.
Function Leap (x:year):Boolean;
Begin
Leap:=(x Mod 400 =0) Or (x Mod 100<>0) And (x Mod
4=0);
End;
121

.

:
Function DayM(x:year;y:month_number):day;
Begin
Case Of
4 , 6 , 9 , 1 1 : DayM: =30; {*B , , 30
. *}
1 , 3 , 5 , 7 , 8 , 1 0 , 12: DayM:=31; {*B , , , , , 31 .*)
2: If Leap(x)Then DayM: =29
Else DayM: =28; {* , 29 .*}
End;
End;
, 30.12.1987, String.
Function StringDate(w:Date):String;
Var s,q:String;
Begin
str(w.dday,s);
If w.dday<l0 Then s:='0'+s;{* . *}
s:=s+'.';
str (w. dmonth,q) ; { * . *}
If w.dmonth<10 Then s:=s+'0'+q+'.'
Else s:=s+q+'.';
str (w.dyear,q) ; { * . *}
s:=s+q;
StringDate:=s;
End;
.
, :
;
.
Procedure Tomorrow(:date;Var :date);
Begin
:=;
If x.Dday<>DayM(x.dyear,x.dmonth)
Then y.dday:=x.dday+l
{* . *}
Else If x.dmonth<>12
Then Begin
.dmonth:=x.dmonth+l;
{* .
*}
.dday:=1;
End
Else Begin
.dyear:=x.dyear+1;
.dmonth: =1;
.dday:=1;
End;
End;
, ,
(), , .
, w ...
Procedure Future(x:Integer;Var :Date);{*
, . *}
122

.

Var i:Integer;
Function Dyears(z:year):Integer;{* . *)
Begin
If Leap(z) Then Dyears:=366
Else Dyears:=365;
End;
Begin
For i:=l To y.dmonth-1 Do x:=x+DayM (y. dyear , i ) ;
{* ,
.*}
:=+.dday; { * .
*}
While x>Dyears(.dyear) Do Begin{* . *}
x:=x-Dyears(.dyear);
Inc
(.dyear) ;
End; { *
. *}
.dmonth :=1; { * . *)
While x>DayM(.dyear,y.dmonth) Do
Begin {* . *)
: =x-DayM(. dyear,. dmonth);
Inc(.dmonth);
End; {* . *}
.dday:=x; {* . *}
End;

:
Program Pr20_l;
Var t,r:date; w:Integer;
{* . *)
Begin
WriteLn(' , , : ') ;
ReadLn( t . dyear,t.dmonth,t.dday);
Tomorrow(t,r);
WriteLn(StringDate(r)) ;
WriteLn(' .'); ReadLn(w);
Future(w,t);
WriteLn(StringDate(t));
End.
.
2. .
. . . , Real ,
=b, b , .
-, , .
Type TPoint=Record , : Real; End;
Const Eps:Real=1e-7;{* .*}
ZeroPnt:Tpoint= (x:0; :0);{* 0,0. *}
:
123

.

Function RealEq(a, b: Real): Boolean; {* . *}
Begin
RealEq:=Abs(a-b)<=Eps;
End;
:
Function EqPoint(, :TPoint):Boolean;{* ?*}
Begin
EqPoint:=RealEq(., .) And RealEq (., .);
End;
.
Function Dist (,:TPoint): Real;{*
. *}
Begin
Dist:=Sqrt(Sqr(A.x-B.x) + Sqr(A.y-B.y));
End;
(v) ,
(0,0) (,). v
() v .
(v) (,
) :
x=v*cos (a), y=v*sin (), v= x 2 + y 2 , tan ()=/.

( ) .
Function GetAngle (w:TPoint) :Real; { *w . *}
Var v,angle:Real;
Begin
v:=Dist(w,ZeroPnt); {*. *}
If RealEq(v,0)
Then GetAngle:=0
Else Begin
If RealEq(w.x,0)
Then If w.y>0
Then angle:=Pi/2
Else angle:=3*Pi/2 {* .
. *}
Else If RealEq(w.y,0)
Then If w.x>0
Then angle:=0
Else angle:=Pi
Else Begin
angle:=ArcTan(Abs(w.y/w.x));
{* . *}
If w.x*w.y>0
Then Begin If w.x<0
124


Then angle:=Pi+angle;
End
Else If w.x<0
Then angle:=Pi/2+angle
Else angle:=2*Pi-angles;
End;
GetAngle:=angle; End; End;
,
.
, ,
. , (v,w)= v*w*Cos(a),
a - v w.
, v, w : Cos(a)=(v.x*w.x+v.y*w.y)/(v*w). , (v,w)= v.x*w.x+v.y*w.y.
Function ScDec(v,w:TPoint): Real; {*
. *}
Begin ScDec:=v.x*w.x+v.y*w.; End;
((v,) (w,)) :
v*w = v.x*w.x + v.y*w.y = v*Cos(a)*w*Cos()+v*Sin(a)*w*Sin() =
v*w*Cos(a-).
,
,
;
, , ,
.
, } 2, : (p2.x-p1.x)*(yp1.y)=(p2.y-p1.y)*(x-pl.x). : -(p2.y-p1.y) *x
+(2.-1.)*+(2.-1.)* 1. - (2.-1.) * 1.=0, A*x + * + = 0,
.
1*+1*y+C1=0
2*+2*+2=0, ,
(1*22*1 <>0), :
=-(C1 *2-2*1) / (1*2 - 2*1) , = (2*1-1 *2) /
A1*B2 -A2*B1)
:
Line=Record ,,: Real; End;
,

.
Procedure Point2ToLine (, : TPoint; Var L: TLine);
{* .
*}
Begin
L.A:=B.y-A.y;
L.B:=A.x-B.x;
L.C:=- (A.x*L.A + A.y*L.b);
End;
Function Line2ToPoint(fL,sL:TLine; Var P: TPoint): Boolean;
{* .
True, , False, . *}
125

.

Var s t : Real;
Begin
st:=fL.A*sL.B-sL.A*fL.B;
If Not(RealEq(st,0) )
Then Begin Line2ToPoint:=True;
P.x:=-(fL.C*sL.B-sL.C*fL.B)/st;
P.y:=(sL.A*fL.C-fL.A*sL.C)/st;
End
Else Line2ToPoint:=False;
End;

1.

2.
3.
4.

5.

( ) :
;
, m ;
, t l t 2 ;
, tt (
);
(1900-2000), ;
, .
( ). ,
.
. , 100. .
, :
Type time=Record
h:0..23;
m,s:0.. 5 9
End;
:
, t t t 2 (
);
, tt , 1 t
( ).
:

Const =300; Type MyRecord = Record key: Integer; name : String;End;


Vector=Array[l..n]Of MyRecord.
, , :
, key;
(t,k,h), , t (
key) key, k, , , h.
6. , ( ). :
;
.
7. .
, (
). : ( ) ( ). :
, 0,3 ;
126

, , , ;
, 30 .
8.
( ) . Type TPol=Record r,ang:Real; End.
:
{* . *}
Procedure TurnDecPol(w:TPoint; Var q:TPol);
{* . *}
Procedure TurnPolDec(q:TPol; Var w: TPoint);
9. , ()
.
:
{* . *}
Procedure AddPol(a, b: TPol; Var : TPol);
Begin
.ang:=(a.ang+b.ang)/2;
C.r:=Sqrt (Sqr(a.r*Cos(a.ang)-b.r*Cos (b.ang))+ Sqr (a . r*Sin (a . ang) -b.
r*Sin (b. ang))) ; End;
10. {pltp2)
t: p.x=p 1 .x+(p 2 .x-p 1.x)*t u p.y=p 1 .y+(p 2 .y-p 1 .x)*t.

0tl (.) , t<0 t>l ,


.
, ,
. , ?
11. . , ,
=(,). p 1 =(x 1 ,y 1 ) p2 =( 2 , 2 ),
p 3=(3,3) 4=(4,4). .

12. N . .
13. . .
14. . .
15. , . .
16. . , , , , , .
17. .
.
18. . .

127

19. . .
20. . ,
.

1. .
2. .

21. :

1. (. Pascal. I.
. 2, . 37-50);
2. ;
3. ;
4. :
(. . 46);
(. . 47-48);
:
(. . 48-49);
5. .


- ( ).
. , 0. ( ) .
.
Write(f, ); f .
Read(f, ); f
.
Seek(f, n); f n- . 0.
FileSize(f): longint; f.
FilePos(f): longint; f.
Truncate(f); ,
.
Assign(f, FileName) f , FileName.
, ,
.

128

Close(f) - f. Close .
- Close , -
,
.
EOF(f): boolean - TRUE,
. ,
.
Rename(f, NewName) -
, f.
.
Erase(f) - ,
f. Erase .
IOResult - , - . 0. IOResult - , . IOResult
- {$I-}.

1. . ,
3. .
2. . :
;
, a;
;
, b. , ;
. ,
.
3. , .
, .
, , . .
, , .
()
4. , .
, . , , , , .
, .
5. . , (, ).
6. . 100
100.
7.
,
129

. 30. , :
;
, 5;
, ;
, . ,
, .
8. 20 .
, . , :
;
;
;
.
.
.
9. 15 , 5 10 .
, ()
, .
.
, .
, .
, .

130


1. .., .., .. . - .:
- 1988 - 320.
2. .., .. .
.: . . . . .- .:..,
1991. 160 .: .
3. .. : . 2- ., .
. .: - . .., 2002. 416 .
4. .. Turbo Pascal. .: , 2002.- 496 .: .
5. .., .. Turbo Pascal 7.0. - .:
, .: , 1997. - 496 .
6. .. . .:, 2002. 424
.: .
7. : . . . - .: . , 1991. - 400 .
8. .. . :
. .: , 2003. 393 .
9. . : . - .:
, 1987. - 232 .
10. : / . .. .: , 2002. 336 .: .
11. .., .. Turbo Pascal . .:
-, 2005. 352 .: .
12. .. - . .: -,
2002. 432 .: .
13. .., .. . .: 1993 208 .
14. .-., . . - .:
, 1989. - 299.
15. Turbo Pascal 7.0. - : BHV, 1996. - 448 .

131

Оценить