You are on page 1of 115

1

.., ..



, 1994

519.682.2
973-018.2()73
.., .. : .
-,1995.- 169 .

, IBM PC,
.
,
- .
,
, ,
.
. 33, . 8, .

: .-.., . ..

1.
1.1.
1.1.1.
1.1.2.
1.1.3.
1.1.4.
1.1.5.
1.2.
1.2.1
1.2.2.
1.2.3.
1.2.4.

2
1.2.5.
1.2.6.
1.2.7.
1.2.8. ()
1.2.9.
1.2.10.
1.2.11.
1.2.12.
1.3.
1.3.1.
1.3.2.
1.3.3.
1.3.4.
1.3.5. sizeof
1.3.6.
1.3.7.
1.3.8.
1.3.9.
1.3.10.
1.3.11.
1.3.12.
1.3.13.
1.3.14.
1.3.15.
1.3.16.
1.3.17.
1.3.18.
1.4.
1.4.1.
1.4.2.
1.4.3.
1.4.4. if
1.4.5. switch
1.4.6. break
1.4.7. for
1.4.8. while
1.4.9. do while
1.4.10. continue
1.4.11. return
1.4.12. goto
1.5.
1.5.1.
1.5.2.
1.5.3. main
1.6.
1.6.1.
1.6.2.

3
1.6.3.
1.6.4.
1.7.
1.7.1.
1.7.2.
1.7.3.
1.7.4.
1.7.5.
1.8.
1.8.1. #include
1.8.2. #define
1.8.3. #undef
2.
2.1.
2.1.1.
2.1.2.
2.1.3.
2.1.4.
2.1.5.
2.1.6.
2.2.
2.2.1.
2.2.2.
2.2.3.
2.2.4.
2.2.5.
2.2.6.
2.3.
2.3.1.
2.3.2.
2.3.3. -
2.3.4.
2.3.5.
2.4.

htm- .. ..
- .

1.

1.1.
1.1.1.
.
1. , (.1).
,
. ,
, .
1

ABCDEFGHIJKLMNOPQRS
TUVWXYZ
abcdefghijklmnopqrstuvwx
yz
_

2. (.2).
2


0123456789
3. (. 3).
, -
.
2

,
.
;
:
?
'
!
|
/
\

)
(
}
{
<
>
[
]
#
%

5
~
*
+
-

&
^
=
"

4. . : ,
, , , .
, ,
.
( ).
5. ,
, .. ,
.
(\)
( ) (.4).
4

\a
\b
\t
\n
\v
\r
\f
\"
\'
\0
\\
\ddd
\xddd

007
008
009
00A
00B
00C
00D
022
027
000
05C

\ddd \xddd ( d )

.
:
\r - ,
\015 - ,

6
\x00D - .
,
.
\n ( ) \010 \xA,
,

. :
"ABCDE\x009FGH"
, ABCDE FGH, 8-
,
"ABCDE\x09FGH", ABCDE=|=GH,
\x09F "=+=".
, ,
(.. .4)
, ,
. :
\h h .
,
(\) . (\) (\n),
, .
.
1.1.2.
.
: , ,
.
: , ,
: ,
.
,
(
).

( ,
).
0 0
(
: 0,1,2,3,4,5,6,7,8,9,A,B,C,D,E,F)
:

16
020

0x10

7
127
240

0117
0360

0x2B
0XF0

, "-"
( ). :
-0x2A, -088, -16 .
, ,
, .
:
- ,
int () long ( ) .
32768, int long.
- int, unsigned int
( ), long unsigned long
5.
5

0x0 - 0x7FFF
0X8000 - 0XFFFF
0X10000 - 0X7FFFFFFF
0X80000000 - 0XFFFFFFFF

0 - 077777
0100000 - 0177777
0200000 - 017777777777
020000000000 - 037777777777

int
unsigned int
long
unsigned long

long,
"l" "L". :
5l, 6l, 128L, 0105L, OX2A11L.
- ,
. :
[ ].[ ] [ |e [+|-] ] .
() .

( double).
,
.
: 115.75, 1.5-2, -0.025, .075, -0.852
- .
,
.
. :

8
' '- ,
'Q'- Q ,
'\n' - ,
'\\' - ,
'\v' - .
int .
() - (
) (") .
: " N 35", " ", "YZPT ".
, , ("), (\)

.
. ,
" \n N 35" "" , "N
35" .
.
,
\0.
char[] . ,
. ,
1, ( )
.
. .

. ,
, . :
" \n
"

" " .
( ) .
,
, .

.
1.1.3.

9
,
, , .

.
(_).
, . : abc, ABC,
A128B, a128b .
,
, 31 .
, , ..
.
.
, ,
.
, (_)
,
, , ,
() , ,
, ..
.
, ,
,
(, ,
).
1.1.4.
- ,
.
.

auto
register
unsigned
volatile

double
tupedef
default
continue

int
char
for
enum

struct
extern
signed
short

break
return
union
while

else
void
do

long
case
if

switch
float
sizeof

,
:
_asm, fortran, near, far, cdecl, huge, paskal, interrupt .
far, huge, near
. _asm, cdelc, fortran, pascal
,
.
.

10
1.1.5.
- , ,
, , . ,

, (/* */). ,
, . :
/* */
/* */

/* ,
, ,
, ,
*/

.
/* /* */ */

/* */ */

1.2.
(PL1, FORTRAN, .)
,
.
:
[--] -
[=] [, [= ] ]...

-
, ( ).
- ,
. ,
() .
- ,
() .
- :
auto, extern, register, static, ,
, , ,
, .., .
1.2.1

11
:
char
int
short
long
signed
unsigned

:
float
double
long double

.
const -. const
, ..
. , const
-, int. const
(, , , ),
, , ..
.
:
const double A=2.128E-2;
const B=286; ( const int B=286)

.
1.2.2.
,
,
(. 6).
6



char
1
-128 127
int
IBM XT,AT,SX,DX 2
short
2
-32768 32767
long
4
-2 147 483 648 2 147 483 647
unsigned shar
1
o 0 255
unsigned int IBM XT,AT,SX,DX 2
unsigned short
2
0 65535
unsigned long
4
0 4 294 967 295
, signed unsigned . ,
, ..,
unsigned, ,
.
unsigned . ,
signed unsigned
, int. :
unsigned int n;

12
unsigned int b;
int c;
(
unsigned d;
(
signed f;
(

signed
int c
unsigned int d
signed
int f

);
);
).

, - char (
) .
char ( 1 ),
. ,
unsigned char,
127.
:
- int unsigned int.
signed int
, . , 16-
2- , 32-
4- , .. int short int, long int
. ,
.

sizeof , -.
:
a
b
c
d

=
=
=
=

sizeof(int);
sizeof(long int);
sizeof(unsigned long);
sizeof(short);

,
unsigned. u U ,
.
:
0xA8C
01786l
0xF7u

(int signed
);
(long signed
);
(int unsigned );

1.2.3.
,
- : float, double, long double ( long double
).
- float 4 . 1
, 8 23 . ,
1, ,
3.14E-38 3.14E+38.
double 8 . float.
: 1 , 11 52

13
.
1.7E-308 1.7E+308.
:
float f, a, b;
double x,y;

1.2.4.
- , (
, , ,
). , ,
, .
, ,
,
( ). :
- [ ] * .
- ,
, ( ). -
void, ,
. , void,
. ,

, ,
.
.

const, near, far, huge. const ,
. ,
,
.
.
near, far, huge.
:
unsigned int * a; /*
unsigned int ( ) */
double * x;
/*

*/
char * fuffer ;
/* fuffer
char */
double nomer;
void *addres;
addres = & nomer;
(double *)addres ++;
/* addres .
(& - ).
, ,
,

14
, .
, (double *)
addres double, .

*/

const * dr;
/* dr , ..
,
, , . */
unsigned char * const w = &obj.
/* w char
unsigned. ,
w .
. */

1.2.5.
, ,
.
enum
.
1. enum [--] {-} [,...];
2. enum -- [,..];

, -.
.

. int. ,
,
int.
enum
.
1 .
--, ,
, .
.
.
- :
[= ]
.
enum .
0, - 1
.. .

15
, , ,
. int
, .
, 1,
.
:
1. .
2.
,
.
3. ,
.
4. .
:
enum week { SUB = 0,
VOS = 0,
POND,
VTOR,
SRED,
HETV,
PJAT
}
rab_ned

/*
/*
/*
/*
/*
/*
/*
;

0
0
1
2
3
4
5

*/
*/
*/
*/
*/
*/
*/

week,
, rab_ned week.
,
- .
.
- ,
.
:
enum week rab1;
typedef
,
.
typedef.
, , ,
.
1.2.6.
- (double, float, int ..).

. :

16
- [ - ];
- [ ];
- .
- .
void.
- .
-
:
- ,
- ,
- , .
,
, .
- ,
- .
-
,
-, - .. ,
0.
:
int a[2][3]; /*
a[0][0] a[0][1] a[0][2]
a[1][0] a[1][1] a[1][2]
*/
double b[10]; /* 10 double */
int w[3][3] = { { 2, 3, 4 },
{ 3, 4, 8 },
{ 1, 0, 9 } };

w[3][3]. , ,
,
.
,
(PL1 ..), .
.
.

, .
:
int s[2][3];

17
s[0],
s.
int b[2][3][4];
b , , b[1][2]
, b[1] 3 4.
b[2][4], , ,
.
.
char str[] = " ";
, ,
'\0'.
1.2.7.
C - , ,
. , ,
. :
struct { }
.
:
- ;
- , .
.
:
struct { double x,y; } s1, s2, sm[9];
struct { int
year;
char moth, day; } date1, date2;

s1, s2 ,
. sm .
date1, date2 year, moth, day. >p>
,
. .
:
struct { ; };
.
student :
struct student { char name[25];

18
int id, age;
char prp;

};


:
struct -;
:
struct studeut st1,st2;
.
.
struct node { int data;
struct node * next; }

st1_node;

node ,
, .. next.
, .. node ,
node, ,
, .

, :
st1.name="";
st2.id=st1.id;
st1_node.data=st1.age;

1.2.8. ()
,
( ) .
:
union {

1;
...
n; };

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

19
- ,
.
, , ,
.
,
.
, .
:
union {

union {

char fio[30];
char adres[80];
int
vozrast;
int
telefon;
} inform;
int ax;
char al[2];
}
ua;

infor union
, .. inform.fio,
. ua
ua.al[0] ua.al[1] ua.ax .
1.2.9.
,
. .
.
:
struct { unsigned 1 :
unsigned 2 :

-
-

1;
2;

- .
, .
.
:
struct { unsigned
unsigned
unsigned
unsigned

a1
a2
a3
a4

:
:
:
:

1;
2;
5;
2;

} prim;

.
,
.
, .
,
.
1.2.10.

20
,
. , ,
. ,
, .
.
,
.
struct figure {
double area,perimetr;
int type;
union
{ double radius;
double a[2];
double b[3];
} geom_fig;
} fig1, fig2 ;

/*
/*
/*
/*
/*
/*

*/
*/
*/
*/
*/
*/

figure : area,
perimetr, type. type ,
, geom_fig
. ,

( type).
, type int,
. ,
enum figure_chess { CIRCLE,
BOX,
TRIANGLE

} ;

CIRCLE, BOX, TRIANGLE 0, 1, 2.


type :
enum figure_chess type;

, , ,
figure.type = 40;
:
, .
, :
struct { ;
;
union { 1 ;
2 ;
:::
n ;
} - ;
} - ;

21
helth_record
struct { /* */
char name [25];
/*
*/
int
age;
/*
*/
char sex;
/*
*/
/*

*/
/*
( )
*/
enum merital_status ins;
/* */
union {
/*
*/
/* */
struct { /* */
char marripge_date[8];
char spouse_name[25];
int no_children;
} marriage_info;
/* */
char date_divorced[8];
}
marital_info;
} health_record;
enum marital_status { SINGLE, /*
*/
MARRIGO, /*
*/
DIVOREED /* */
} ;

:
helth_record.neme,
helth_record.ins,
helth_record.marriage_info.marriage_date .

1.2.11.
, ,
. ,


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

22
(
) ( ).

. ,
. ,
.
,
" ", .
1. , .
2. ,
.
3. ,
,
.
4. .
:
int
6

* ( * comp [10]) ();


5
3
1
2
4

comp (1), (2)


(3) (4), (5) (6).
char
7

* ( * ( * var ) () ) [10];
6
4
2 1
3
5

var (1) (2) (3)


(4) (5) 10 , (6)
char.
, .
. -
, ,
. -
typedef.
typedef,
, ,
.
, typedef,
, . typedef
, ,
, .
:

23
typedef double (* MATH)( );
/* MATH - ,
, double
*/
MATH cos;
/* cos ,
double
*/
/*
*/
double (* cos)( );
typedef char FIO[40]
/* FIO -
FIO person;
/* person -
/*
char person[40];

*/
*/
*/

(MATH FIO).
, :
, ,
sizeof ( ).
, ,
.
:
- -;
- - ,
, . (*)
, [] () . , ,
.
.
,
.
1.2.12.
,
. "=" .
1: = ;
2: = { - };
1 ,
2 - .
:
char tol = 'N';
tol 'N'.

24
const long megabute = (1024 * 1024);
megabute
.
static int b[2][2] = {1,2,3,4};
b
.
:
static int b[2][2] = { { 1,2 }, { 3,4 } };

static int b[3[] = { { 1,2 }, { 3,4 } };
,
0, ..
static int b[2][2] = { { 1,2 }, { 3 } };
1 2, 3 0.
,
.
:
struct complex { double real;
double imag; } comp [2][3] =
{ { {1,1}, {2,3}, {4,5} },
{ {6,7}, {8,9}, {10,11} } };

comp
, real imag.
struct complex comp2 [2][3] =
{ {1,1},{2,3},{4,5}, {6,7},{8,9},{10,11} };


:
- - comp2;
- - comp2[0].
1,1 ;
- ( 1) ,
, comp[0]
;

25
- {2,3} comp[1],
;
- {4,5}
3 comp2 .

.
:
union tab { unsigned char name[10];
int tab1;
}
pers = {'A','H','T','O','H'};

pers.name, ,
.
, .

.
char stroka[ ] = "";
7 , ()
'\0', .
, , ,
, .
stroka ,
.
char stroka[5] = "";
stroka , '' '\0'
.
, ,
.
, tab :
union tab pers1 = "";
, , :
'','','','','','\0',
.

26

1.3.
1.3.1.
,
, . ,
.
.
, .
,
, .

. ,
, , .
- , , , , ,
,
, . ,
, .
.
,
. int, long, unsigned int,
unsigned long, .
int. double.
, ,
char,
.

char.
, .
, .
, ,
.
. ,
.
:
-
;
- enum
.
. int, ;

27
- struct union ,
;
- , , ,
;
- , , ,
. -
. ,
, .
, ,
.
- , , ,
, .
, .
,
.
,
:
-1 ([ ])
-1 (,
).
. , ,
.
:
-1 [ -2 ]
,
, -1 -2.
-1 - , , , -2 . , ,
. -1
, -2 . -2
.
, .


(*).
, , ,
,
, ,
. , , arr
double.

28
double arr[10];
, i- arr
rr[i], , , i[a]. i
double i- arr .
arr,
i- . ,
.. arr .
, arr[i] ( i[arr]) i .
.
- , . ,
.

:
-1 [ -2 ][ -3 ] ...
, ..
:
-1 [ -2 ]
,
-3 ..
. , ,
.
:
int mass [2][5][3];
mass[1][2][2].
1. mass[1]. 1
, 53
, int.
mass. (53)
mass.
2. 2 int,
, mass [1].
3. - int, 2
int mass [1][2].
4. , .
int.

29
mass [1][2],
int. mass [1]
.
,
.
. :
. ,
-> .
struct union,
- .
, -
.
. ,
, (->),
,
(*), , ..
->

(* ) .
, .
:
struct tree { float
int
struct tree
elem.left = & elem;

num;
spisoc[5];
*left;
}

tr[5] , elem ;

(.) left
elem. left elem
elem, .. elem
.
() .
:
( - ) .

.
.
:

30
int i;
bouble x;
b = (double)i+2.0;

i
, .
- , .
,
, , ,
, sizeof .

:
1.
(,) .
2. "" (&) .
.
( ),
( ) ( ).

:
-- .
, :
1 -- 2 .
,
(?) (:), :
1 ? 2 : 3 .
. , ,
, .
:
- ( );
~ ();
! ;
* ( );
& ;
+ ;

31
++ ();
-- ();
sizeof .
.

.
( ),
. (
), , .
, , .7,
.
7

*
/
%
+
<<
>>
<
<=
>=
==
!=
&
|
^
&&
||
,
=
*=
/=

32

%=
-=
+=
<<=
>>=
&=
|=
^=

,
( const),
:
- , , ,
;
- , ;
- (->) (.),
;
- (*), ,
;
-
.
, (*), (&), (!), (+) \
.
1.3.2.
,

, .
.
.

33
1. float double.
2. long double, .
3. double, double.
4. char short int.
5. unsigned char unsigned short unsigned int.
6. unsigned long, unsigned long.
7. long, long.
8. unsigned int, .
, ,
, .
:
double
ft,sd;
unsigned char ch;
unsigned long in;
int
i;
....
sd=ft*(i+ch/in);


. ch unsigned int ( 5).
unsigned long ( 6). i
unsigned long ,
unsigned long. double ( 3)
double.
1.3.3.
(-) .
.
.
:
double u = 5;
u = -u;

/* u ,
.. u -5
*/

"" (!) 0,
( ), 1, (0). int.
.
:
int t, z=0;

34
t=!z;

t 1, z 0
().
(~) .
.
, .
:
char
unsigned char
b = ~f;

b = '9';
f;

'9' 39. ~f
6, ''.
1.3.4.
.
(*)
. . ,
. ,
. , .
, :
- ;
- ,
;
- , ,
;
- , .
(&) .
. "",
,
. . ,
, .
,
, register.
:
int t, f=0, * adress;
adress = &t; /* adress,
, t */

35
* adress =f; /* ,
adress,
f, .. 0 ,
t=f;
..
t=0;
*/

1.3.5. sizeof
sizeof
. sizeof :
sizeof() .
, ,
. , void,
.
,
(.. ), ,
.
sizeof
,
,
, .
, ,
.
:
struct

{ char
h;
int
b;
double f;
} str;

int a1;
a1 = sizeof(str);

1 , 12,
, , str 7.
,
h 1 , 1 b
( 2 IBM PC AT /286/287),
f (4
),
5 .

, ..
:
struct

{ double f;
int
b;
char
h;
} str;

36
1.3.6.
(*), (/)
(%). (%) . ,
,
.
.
(*) .
int i=5;
float f=0.2;
double g,z;
g=f*i;

i f double,
g.
(/) .
, .
.
int i=49, j=10,
n = i/j;
m = i/(-j);

n, m;

/*
/*

4
-4

*/
*/

(%) .
.
. , .
int
i =
j =
k =
l =

n = 49, m = 10, i, j, k, l;
n % m;
/*
9
n % (-m);
/*
9
(-n) % m;
/*
-9
(-n) % (-m);
/*
-9

*/
*/
*/
*/

1.3.7.
(+) (-).
.
. ,
,
. ,
.
.
:
int

i=30000, j=30000, k;
k=i+j;

k -5536.

37
.
,
- .
,
, , .
,
, ,
.
, .
(-) .
:
1. .
2. .
3. , - .
, ,
, .
:
double d[10],* u;
int i;
u = d+2; /* u */
i = u-d; /* i 2
*/

1.3.8.
(<<) (>>)
, . .
.
.
. unsigned,
.
. ,
.
, ,
. ,
, .
, 2,
, 2
, .
:
int

i=0x1234, j,

k ;

38
k = i<<4 ;
j = i<<8 ;
i = j>>8 ;

/*
/*
/*

k = 0x0234
j = 0x3400
i = 0x0034

*/
*/
*/

1.3.9.
: "" (&),
"" (|), "
" (^).
.
, -
.
(&)
. ,
1, 0.
(|)
. ( )
1, 1,
0.
(^)
. 0,
1, 1,
, .. 1 0, 0.
.
int

i=0x45FF,
j=0x00FF;
char r;
r = i^j;
r = i|j;
r = i&j;

/*

i= 0100 0101 1111 1111


j= 0000 0000 1111 1111

/* r=0x4500 = 0100 0101 0000 0000


/* r=0x45FF = 0100 0101 0000 0000
/* r=0x00FF = 0000 0000 1111 1111

*/
*/
*/
*/
*/

1.3.10.
(&&)
(||). ,
,
.
.
, ,
.
.
.
0 1, int.

39
(&&) 1,
. 0, 0.
0, .
(||) .
0, 0, -
, 1.
, .
1.3.11.
(,)
,
. .
, .
.
. , ,
, ,
.
1.3.12.
- ,
:
-1 ? -2 : -3
-1 .
0. -1 0,
-2 . -1
0, -3 .
, -2, -3, .
-2 -3, .
1. -2 -3 (,
), .
.
2. -2 -3 ,
, ,
.
3. void, void.
4. ,
vold, vold,
.
5. ,
0, .
:

40
max = (d<=b) ? b : d;
max d b.
1.3.13.
(++) (--)
.
.
.
() . .
, .

(), ,
() , .
( ),

.
( ),
,
.
:
int t=1, s=2, z, f;
z=(t++)*5;

t*5, t. z=5,
t=2.
f=(++s)/3;

s , .
s=3, f=1.
,
, .
z++; /* */ ++z;
1.3.14.
,
.
, .
.
:
int t;
char f;

41
long z;
t=f+z;

f long, f+z ,
int t.
1.3.15.
, ,
.
:
(-1) ( ) = (-2) .

:
(-1) = (-1) ( ) (-2) .
,
, -1
.
,
. (+=)
(-=) , .
:
double arr[4]={ 2.0, 3.3, 5.2, 7.5 } ;
double b=3.0;
b+=arr[2];
/*
b=b+arr[2]
arr[3]/=b+1;
/*
arr[3]=arr[3]/(b+1)

*/
*/

,
,
.
1.3.16.
.
1.
. 8.
8

2
1

() [] . ->
- ~ ! * & ++ -sizeof

42
3
4
5
6

*/%
+<< >>
< > <= >=

== !=

&

10
11
12
13

|
&&
||
?:
= *= /= %=
+= -= &= |=
>>= <<= ^=

14
15

()

1.3.17.
,
.
, ( ).
, . ,
:
prog (a,a=k*2);
, ,
.

,
, .
, i*j+(j++)+(--i)
.
.
1. ,
.
2. ,
.
1.3.18.

43

:
-
( );
- ,
;
- .
, .
, ,
, .
, .
.
, .
, .
,
.
]
, long int unsigned
long int float, .
.
.

.
,
. , , ,
( 1), ..
, .
,
signed long, signed long
. unsigned long float, double long double
, ,
, long.
. float double
. double long double float c
. float,
, .

long ( ),
long .
long, .

44
float, double long double unsigned long
, ,
, long.
.
.
- .
void ,
void .
.
:
- ,
, ;
- , ,
, , .
:
- , ,
( );
- ,
( ,
), .
. ,
, , (
"") .
,

.
.
float double, char short int,
unsigned char unsigned short unsigned int.
.
,
.
.
, :
( - ) .
- ,
.
:

45
int
i=2;
long
l=2;
double
d;
float
f;
d=(double)i * (double)l;
f=(float)d;

i,l,d
.

1.4.
:
- , if switch;
- (for,while,do while);
- (break, continue, return, goto);
- ( "", ).

. ,
.
, ,
";".
1.4.1.
, , .
.
, , ,
. , ,
.
.
:
++ i;

46
, i
.
a=cos(b * 5);
,
.
a(x,y);
.
1.4.2.
.
. :
- do, for, while, if , ,
;
- .
, .
. ,
, .
:
int main ( )
{
:
{ if (...) goto a;
{ ...
}
a:; }
return 0;
}

/* */

1.4.3.
,
:
{

[o]
:
; [];
:

, .

.
:

47
int main ()
{
int
q,b;
double t,d;
:
if (...)
{
int
e,g;
double f,q;
:
}
:
return (0);
}

e,g,f,q . ,
q , ..
q main int. ,
return ,
.
1.4.4. if
:
if () -1; [else -2;]
if .
:
- (.. 0), -1.
- (.. 0), -2.
- -2 (
), if .
if ,

.
:
if (i < j)
i++:
else { j = i-3;
i++; }

, -1,
-2 .
if. if
if else if.
,
if, . ,

48
else if,
else.
:
int main ( )
{
int t=2, b=7, r=3;
if (t>b)
{
if (b < r) r=b;
}
else r=t;
return (0);
}

r 2.
, if,
:
int main ( )
{
int t=2,b=7,r=3;
if ( a>b )
if ( b < c ) t=b;
else
r=t;
return (0);
}

r 3, else
if, , ,
if.
if:
char ZNAC;
int x,y,z;
:
if (ZNAC == '-') x = y - z;
else if (ZNAC == '+') x = y + z;
else if (ZNAC == '*') x = y * z;
else if (ZNAC == '/') x = y / z;
else ...

,
if,
.
switch.
1.4.5. switch
switch
. :
switch ( )
{
[]

49
:
[ case -1]: [ -1]
[ case -2]: [ -2]
:
:
[ default: [ ]]
}

, switch ,
, , .
, ,
, .
.
smitch , case
-. ,
,
.
,
.
.
switch .
, case, , ,
default.
, .
switch
.
, switch ,
case,
.
switch :
- ;
- ,
case;
- ,
, case;
- ,
, default,
switch .
switch:
default switch. case
default switch ,
switch. ,

50
, ,
- switch.
, case,
. break.
, ,
case.
:
int i=2;
switch (i)
{
case 1: i
case 2: i
case 0: i
case 4: i
default:

+=
*=
/=
-=

2;
3;
2;
5;
;

switch , case 2.
, i , 6, ,
case 0, case 4, i 3,
-2. , default,
.
,
if, switch.
char ZNAC;
int x,y,z;
switch (ZNAC)
{
case '+': x
case '-': x
case '*': x
case '/': x
default : ;
}

=
=
=
=

y
y
y
u

+
*
/

z;
z;
z;
z;

break;
break;
break;
break;

break
switch,
, switch.
, switch switch,
case
.
:
:
switch (a)
{
case 1: b=c; break;
case 2:
switch (d)
{
case 0: f=s;

break;

51
case 1:
case 2:

f=9; break;
f-=9; break;

}
case 3: b-=c; break;
:

1.4.6. break
break
switch, do, for, while. break
, .
1.4.7. for
for - .
:
for ( 1 ; 2 ; 3 )
1 ,
. 2 - , ,
. 3 ,
.
for:
1. 1.
2. 2.
3. 2 (), ,
3 2, 2
(), , for.
, . ,
,
.
:
int main()
{ int i,b;
for (i=1; i<10; i++)
b=i*i;
return 0;
}

1 9.
for
, .
:

52
int main()
{ int top, bot;
char string[100], temp;
for ( top=0, bot=100 ; top < bot ; top++, bot--)
{ temp=string[top];
string[bot]=temp;
}
return 0;
}

, ,
top bot. ,
1 3 ,
, .
for .
,
break.
:
for (;;)
{ ...
... break;
...
}

, for
.
.
:
for (i=0; t[i]<10 ; i++) ;
i
t, 10.
1.4.8. while
while :
while () ;
,
, .
while :
1. .
2. , while
. ,
while.
3. 1.

53

for (-1; -2; -3) ;
while :
-1;
while (-2)
{
-3;
}

for, while
. while ,
.
for while ,
.
1.4.9. do while
do while
, .
:
do while ();
do while :
1. ( ).
2. .
3. , do while
. ,
1.
, ,
break.
while do while .
:
int i,j,k;
...
i=0; j=0; k=0;
do { i++;
j--;
while (a[k] < i) k++;
}
while (i<30 && j<-30);

1.4.10. continue

54
continue, break, ,
,
, .
:
continue;
:
int main()
{
int a,b;
for (a=1,b=0; a<100; b+=a,a++)
{ if (b%2) continue;
...
/*
}
return 0;
}

*/

1 , continue
for, .
continue, break,
.
1.4.11. return
return , ,
, , .
main . :
return [] ;
, ,
. ,
. ,
.
- return,

. .
, void.
, return
, .
:
int sum (int a, int b)
{
renurn (a+b);
}

sum a b int,
int, , .
return .

55
:
void prov (int a, double b)
{ double c;
if (a<3) return;
else if (b>10) return;
else { c=a+b;
if ((2*c-b)==11) return;
}
}

return
.
1.4.12. goto
goto
,
.
:
goto -;
...
-: ;

goto , -.
, goto,
, .. -
. - - .
.
goto, .
,
,
.

1.5.1.

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

56
( )
( ),
. ( !) .
,
, .

. , ,
, ...
-
( , ), (
) .
, ,
, ,
, .
.
:
int rus (unsigned char r)
{ if (r>='' && c<=' ')
return 1;
else
return 0;
}

rus, r
unsigned char. , 1,
, 0 .
,
.
main, , .
,

() .
, ,
, ,
. , ,

int rus (unsigned char r); rus (unsigned char);


, ,
, .. .
,
,
#include.

57
,
, .

. .
, ,

.

" ",
, . , rus
:
int rus (r)
unsigned char r;
{ ...
/*

*/

...

:
[--] [-] -
([--])
{ -
}

-- ,
static extern.
.
-
. - , ,
int.
,
, . ,
,
.
return,
. , ,
,
. return
(
return), . ,
, void,
. ,
, return
,
.
-- -
, . - ,

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

58
, . ,
, , ,
.
,
.
, ,
void.

.
.
, , ,
, . ,
int.
register,
int .

.
, ,
.
, ,

.
int, .. char
int. ,
, double.
,
, .
.
- , ,
.
, ,
auto, .. .
.
,
, return
. , ,
.
,
.

,
.
. ,

59
,
. ,
,
.
:
/*

void change (int x, int y)
{
int k=x;
x=y;
y=k;
}

*/

x y, ,
,
change, , ,
.
.
:
/*

void change (int *x, int *y)
{ int k=*x;
*x=*y;
*y=k;
}

*/


,
change (&a,&b);
,
,
. ()
:
[--] [-] - ([-]) [,--];
,
, .
,
,
-, --,
.
, .
,
, .

60
- , .

.
, ,
.
int,
.
, :
1. , int.
2. ,
.


, , ,
.
, ,
.
static,
static. ,
extern.
:
- ([-])
,
- (
), .
- ,
. , .
, ,
, .
,
.
:
1.
. , ,

. ,
, .
,

61
.
. ,
, , .
2.
.
3. .
4. return ,
. return
,
.
, .
.
:
int (*fun)(int x, int *y);
fun : int
int. int. ,
fun *, ,
int *fun (intx,int *y);
fun int.
fun
:
(*fun)(i,&j);
, fun
* .
.
,
. ,
.
:
double (*fun1)(int x, int y);
double fun2(int k, int l);
fun1=fun2;
/* */
(*fun1)(2,7);
/*
*/

fun1
, double, fun2.
, ..
, .

62

cos(x).
:
double proiz(double x, double dx, double (*f)(double x) );
double fun(double z);
int main()
{
double x;
/*
double dx;
/*
double z;
/*
scanf("%f,%f",&x,&dx); /* x dx
z=proiz(x,dx,fun);
/*
printf("%f",z);
/*
return 0;
}
double proiz(double x,double dx, double (*f)(double z) )
{
/* */
double xk,xk1,pr;
xk=fun(x);
xk1=fun(x+dx);
pr=(xk1/xk-1e0)*xk/dx;
return pr;
}
double fun( double z)
{
/* */
return (cos(z));
}

*/
*/
*/
*/
*/
*/

-
fun proiz .
, cos(x) proiz

z=proiz(x,dx,cos);
sin(x)
z=proiz(x,dx,sin);
, ..
. .
auto register
,
, .
, static,

.
- n! :
n! = 1 n=0;
n*(n-1)!

n>1 .

, , :

63
long fakt(int n)
{
return ( (n==1) ? 1 : n*fakt(n-1)
}

);

,

.
1.5.2.

.

.
, , .
, , ,
.

, .

, - (printf,scanf
..). .
.

() va_start, va_arg, va_end,
stdarg.h. , ,
, ,
.
.
va_start, va_arg, va_end
.
va_start arg_ptr
:
void va_start(arg_ptr,prav_param);
prav_param
, arg_prt
va_list :
va_list arg_ptr;
va_start va_arg.
va_arg

type_arg va_arg(arg_ptr,type);

64
type , arg_ptr,
arg_ptr ( type)
arg_ptr
. va_arg ,
.
va_end
(NULL).

.
-1.
,
.
:
#include
int main()
{ int n;
int sred_znach(int,...);
n=sred_znach(2,3,4,-1);
/* */
printf("n=%d",n);
n=sred_znach(5,6,7,8,9,-1);
/*
*/
printf("n=%d",n);
return (0);
}
int sred_znach(int x,...);
{
int i=0, j=0, sum=0;
va_list uk_arg;
va_start(uk_arg,x); /* uk_arg
/*
if (x!=-1) sum=x;
/*
else return (0);
j++;
while ( (i=va_arg(uk_arg,int))!=-1)
/*
*/
{
/* */
sum+=i;
/*
*/
j++;
}
va_end(uk_arg);
/*
return (sum/j);
}

*/
*/
*/

*/

1.5.3. main
main, -,
, , ,
. , ,
.
main ,
, . (
) argc argv. argc int,

65

, (
). argv ,
.
, .
main , argp,
main ()
-.
main :
int main (int argc, char *argv[], char *argp[])
, , - :
A:\>cprog working 'C program' 1
argc, argv, argp .1.
argc
argv

[ 4
[

]
]--> [
]-->
[A:\cprog.exe\0]
[
]-->
[working\0]
[
]-->
[C program\0]
[
]-->
[1\0]
[NULL]
argp [
]--> [
]-->
[path=A:\;C:\\0]
[
]-->
[lib=D:\LIB\0]
[
]-->
[include=D:\INCLUDE\0]
[
]-->
[conspec=C:\COMMAND.COM\]
[NULL]
.1.

argc, argv, argp,



main.
,
main
.
:
int main ( int argc, char *argv[], char *argp[])
{ int i=0;
printf ("\n %s", argv[0]);
for
(i=1; i>=argc; i++)
printf ("\n %d %s", argv[i]);
printf ("\n
:");
while (*argp)
{ printf ("\n %s",*argp);
argp++;
}
return (0);
}


geteuv, :

66
char *geteuv (const char *varname);
,
geteuv. ,
NULL.
, geteuv,
, .
puteuv.
- ,
, , ,
, main,
. _setargv _seteuv,
main.
-
,
_setargv _seteuv - main
, ().
:
_setargv()
{ return ;
/* */
}
-seteuv()
{ return ;
/* */
}
int main()
{
/* */
...
...
renurn (0);
}

_setargv _seteuv

. exe-.

1.6.1.
- main,
.
,
.

.
( ), ,
.

67
,
.
. ,
, .2., main
fun1, fun2, fun3,
.
main ()
{ ...
}
fun1()
{ ...
}

fun2()
{ ...
}
fun3()
{ ...
}

file1.c
file2.c
.2.
, ,
.
. ,
.
. ,
,
.
, ,
. -
, , ,
( ,
).
, .
, - .
- ,
( ) .
.

,
.
,
.
, .

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

68
, ,
. ,
.

, .
auto, register, static
extern. ,
.
auto register . static
extern .

, ,
auto.
auto ,
.
.
.
auto .
.
auto
.
register
, .
. ,
register, ,
auto. , ,
, ,
,
auto. register int
, int.
, static,

.
, .
auto, ,
static ,
.
:
i
static.
/*
file1.c
*/
main()
{ ...
}
fun1()
/*

*/

69
{ static int
}
/*
fun2()
{ static int
}
fun3()
{ static int
}

i=0; ...
file2.c

*/

i=0; ...
i=0; ...

static,
i.
, (), .

.
static
. ,
.
, auto,
.
.
, extern,
,
. ,
.
:
i,
,
*/
/*

file1.c
*/
main()
{ ...
}
fun1()
{ extern long i[]; ...
}
/*

file2.c
*/
long i[MAX]={0};
fun2()
{ ...
}
fun3()
{ ...
}
/*

i[] extern
fun1. file2.c
, extern
.
extern
, , , ..
.
st.

70
:
main()
{ extern int st[]; ...
}
static int st[MAX]={0};
fun1()
{
...
}

extern ,
, -
.

static extern,
. auto register
.
- ,
, .
, ( ),
.
:
1. static.
,
. static int i=0 static int i ,
i 0.
2. , .
static. int i=1
static int i=1 .
,
.
( extern).

.
static,
,
.
extern ,
, ,
, .. .
,
.
extern ,
.
, extern,
.

71
1.6.2.
.
static extern.
.

.
1. , static, ,
. static
, static
. static
, .
2. , extern,
. extern.
3. ,
extern.
extern
,
.
,
.
1.6.3.
( )
.
1. , (.. ),
.
2. (.. ) register
auto, ,
. static extern,
.
.
1. , ,
.
,
extern.
2. , ,
. .
3. ,
, . .

72
, , , ,
, ,
.
4. static ,
. .
.
, ,
.
1.6.4.
:
1. extern
.
2. , ,
.
3. static
. .
,
.
4. auto register
, .
, .
5.
static .

. auto register
.
:
int global_var;
int func(void)
{ int local_var;
static int *local_ptr=&local_var;
static int *global_ptr=&global_var;
register int *reg_ptr=&local_var;
}

/* auto
/*
/*
/*

*/
*/
*/
*/

global_var
,
global_ptr. local_var,
auto func,

local_ptr. reg_ptr
, , ,
local_ptr.

73

1.7.1.
. ,
int array[25],
, array,
() , ..
,
array. arrey ,
, .
, , :
int arrey[25];
int *ptr;
ptr=array;

ptr c,
ptr=arrey ptr=&arrey[0].
.
,
, array[16]=3 array[i+2]=7.
, .
, - .
,
. array[16] 16[array]
.
,
- , .
ptr=array
ptr ptr[16] 16[ptr].

*(array+16)=3 *(array+i+2)=7.

*(array+16) *(16+array).
, ..
. array[16] 16[array]
*(array+16).
(.. )
array ptr.
*array = 2;
array[0] = 2;
*(array+0) = 2;
*ptr = 2;
ptr[0] = 2;
*(ptr+0) = 2;

2,
*array=2 *ptr=2, .

74
1.7.2.
- , ..
, .
.
int arr2[4][3]
arr, .
.
int, , ,

int, .
.3.
arr

arr[0][1]
arr[0][2]
arr[0][0]
arr[1][0]
arr[1][1]
arr[1][2]

arr[2][1]
arr[2][2]
arr[2][0]
arr[3][1]
arr[3][2]
arr[3][0]
.3. .

arr[0]
arr[1]
arr[2]
arr[3]

, arr2[4][3] :
arr,
int.
arr.
arr2[2]
*(arr2+2). int
arr2[1][2]
*(*(arr2+1)+2) (*(arr2+1))[2]. ,
arr arr[0], arr[1], arr[2], arr[3]
.
float arr3[3][4][5]

float float,
float, float.

, .. , - .
,
.
, arr2[1][2] ptr2,
int *ptr2=arr2[0] ptr2[1*4+2] ( 1 2
, 4 ) ptr2[6]. ,
arr2[6] 6
.
arr3[2][3][4] o
, float *ptr3=arr3[0][0]
ptr3[3*2+4*3+4] ptr3[22].

75
,
. ,
- ,
.
struct INDEX {

int i,
int j,
int k }

min_index ;

struct INDEX * find_min (int *ptr1, int l, int m int n)


{
int min, i, j, k, ind;
min=*ptr1;
min_index.i=min_index.j=min_index.k=0;
for (i=0; i*(ptr1+ind)
{ min=*(ptr1+ind);
min_index.i=i;
min_index.j=j;
min_index.k=k;
}
}
return &min_index;
}

1.7.3.
: .
++ --
, .
:
int *ptr, a[10];
ptr=&a[5];
ptr++;
/* a[6] */
ptr--;
/* a[5] */


int. ,
.
:
int *ptr1, *ptr2, a[10];
int i=2;
ptr1=a+(i+4);
/* a[6] */
ptr2=ptr1-i;
/* a[4] */

.
int
, ,
.
:
int *ptr1, *ptr2, a[10];
int i;
ptr1=a+4;

76
ptr2=a+9;
i=ptr1-ptr2;
i=ptr2-ptr1;

/*
/*

5
-5

*/
*/

==, !=, <,


<=, >, >= ,
0 () 1 ().
:
int *ptr1, *ptr2, a[10];
ptr1=a+5;
ptr2=a+7;
if (prt1>ptr2) a[3]=4;

ptr1 ptr2 a[3]=4


.
1.7.4.
, , ,
. .

int a[]={10,11,12,13,14,};
int *p[]={a, a+1, a+2, a+2, a+3, a+4};
int **pp=p;

, .4.
pp

.4. .
a

11

12

13

14

15

pp-p , pp p
, p (
p[0]).
pp+=2 ,
.5.
pp

10
11
12
13
14

.5. pp+=2.
a

pp-p 2, pp
p. *pp-a 2, *pp

77
a, a a.
**pp 12 -
a. *pp++ p ..
a.
, pp=p, *++pp a (..
11), ++*pp p[0], ,
a[1].
. *(++(*pp))
: *pp p[0],
++(*p) p[0]
a[1],
, .. 11.
,
.
int a[3][3]={

{ 11,12,13 },
{ 21,22,23 },
{ 31,32,33 }
int *pa[3]={ a,a[1],a[2] };
int *p=a[0];

};

.6.

.6. .
a[0][0] a, p, pa
: a[0][0], *a, **a[0], *p, **pa, *p[0].
.
char *c[]={ "abs", "dx", "yes", "no" };
char **cp[]={ c+3, c+2 , c+1 , c };
char ***cpp=cp;

.7.

.7. .
1.7.5.

78

calloc.
a[10] float
float *a;
a=(float*)(calloc(10,sizeof(float));


,
. , , a[n][m],
:
#include
main ()
{ double **a;
int n,m,i;
scanf("%d %d",&n,&m);
a=(double **)calloc(m,sizeof(double *));
for (i=0; i<=m; i++)
a[i]=(double *)calloc(n,sizeof(double));
. . . . . . . . . . . .
}


n,m,l. ,
free.
#include
main ()
{ long ***a;
int n,m,l,i,j;
scanf("%d %d %d",&n,&m,&l);
/* -------- -------- */
a=(long ***)calloc(m,sizeof(long **));
for (i=0; i<=m; i++)
{
a[i]=(long **)calloc(n,sizeof(long *));
for (j=0; i<=l; j++)
a[i][j]=(long *)calloc(l,sizeof(long));
}
. . . . . . . . . . . .
/* --------- ----------*/
for (i=0; i<=m; i++)
{
for (j=0; j<=l; j++)
free (a[i][j]);
free (a[i]);
}
free (a);
}

,
, .
,
.
:
#include
main()
{
int vvod(double ***, long **);
double **a;
/*

a[n][m]

*/

79
long *b;
/* b[n]
*/
vvod (&a,&b);
..
/* vvod , */
..
/*
*/
..

}
int vvod(double ***a, long **b)
{
int n,m,i,j;
scanf (" %d %d ",&n,&m);
*a=(double **)calloc(n,sizeof(double *));
*b=(long *)calloc(n,sizeof(long));
for (i=0; i<=n; i++)
*a[i]=(double *)calloc(m,sizeof(double));
.....
}

,
. ,
,
.
:
#include
int main()
{ float *q, **b;
int i, j, k, n, m;
scanf("%d %d",&n,&m);
q=(float *)calloc(m,sizeof(float));
/* q
*/
q[0]=22.3;
q-=5;
/* 5,
*/
/* n-5
*/
q[5]=1.5;
/*
*/
/*
*/
q[6]=2.5;
/* -
*/
q[7]=3.5;
/* -
*/
q+=5;
/* 0,
*/
/* q[0], q[1], q[2]
*/
/* 1.5, 2.5, 3.5
*/
q+=2;
/* -2,
*/
/* -1, 0 ..
*/
q[-2]=8.2;
q[-1]=4.5;
q-=2;
/* ,
*/
/* q[0], q[1], q[2],
*/
/* 8.2, 4.5, 3.5
*/
q--;
/* .
*/
/* */
/* q free(q), */
/* q ,
*/
/* free(q) . */
/*
*/
/* q */
/*
*/
free(++q);

80
/*
*/
/*
*/
b=(float **)calloc(m,sizeof(float *));
for (i=0; i < m; i++)
b[i]=(float *)calloc(n,sizeof(float));
/*
*/
/* b[0][0]
*/
/* ,
*/
/* b[1][1]
*/
for (i=0; i < m ; i++) --b[i];
b--;
/* */
/*
*/
for (i=1; i<=m; i++)
for (j=1; j<=n; j++)
b[i][j]=(float)(i+j);
/*
*/
/* i j, 1 0
*/
/*
*/
for (i=1; i<=m; i++) ++b[i];
b++;
/*
*/
for (i=0; i < m; i++) free(b[i]);
free(b);
...
...
return 0;
}


, double
double.
:
#include
#include
double cos(double);
double sin(double);
double tan(double);
int main()
{ double (*(*masfun))(double);
double x=0.5, y;
int i;
masfun=(double(*(*))(double))
calloc(3,sizeof(double(*(*))(double)));
masfun[0]=cos;
masfun[1]=sin;
masfun[2]=tan;
for (i=0; i<3; i++);
{ y=masfun[i](x);
printf("\n x=%g y=%g",x,y);
}
return 0;
}

1.8.

81
,
, .
, , ,
, ..
#.
.
1.8.1. #include
#include .
:
#include " "
#include < >


,
. ,
, .
,
, PATH.
#include , ..
#include, ,
.
#include
, ,
.
1.8.2. #define
#define , ,
. ,
, .
, , ,
.
#define :
#define
#define


( )

.
.
, .
.
:
#define WIDTH 80
#define LENGTH (WIDTH+10)

82
WIDTH 80,
LENGTH (80+10) .
, , ,
. ,
t=LENGTH*7 t=80+10*7,
t=(80+10)*7, , 780,
630.
#define
, ,
.
.

.

,
.
:
#define MAX(x,y) ((x)>(y))?(x):(y)

t=MAX(i,s[i]);

t=((i)>(s[i])?(i):(s[i]);

, ,
,
, .
,
t=MAX(i&j,s[i]||j);

t=((i&j)>(s[i]||j)?(i&j):(s[i]||j);
-
t=(i&j>s[i]||j)?i&j:s[i]||j;
.

1.8.3. #undef
#undef #define.
#undef
#define
. #undef
, #define.
:
#undef WIDTH
#undef MAX

WIDTH
MAX.

83

2.
2.1.
2.1.1.
- (),
, .
, .
F, D1,D2,...,Dn,
F=,
(..12).
D2 D3 ... Dn
.12. .
D1

, F1=< 2,3,1>,F2=< 7,7,7,2,1,12 >, F3=< >. F1, F2, F3


3,6,0.

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

,
, .

.
F=<7,10>.
d
, , 100, l, ..

84
float d[100];

int l;

100 . F
d :
d[0]=7; d[1]=10; l=2;

.13.
l:
d:

2
7
[0]

10
[1]

...
[2]

[3]

[98]

[99]

.13. .
,
, ( )
dl. ,
.
:
typedef struct snd
{ float val;
struct snd *n ;
} DL;
DL *p;
DL *dl;

/*
*/
/*
*/
/* */
/*
/*

*/
*/


malloc(sizeof(DL)) calloc(l,sizeof(DL)).
:
p=malloc(sizeof(DL));
p->val=10;
p->n=NULL;
dl=malloc(sizeof(DL));
dl->val=7;
dl->n=p;

( )
NULL. .14.

.14. .
2.1.2.
,
, ,
.

d ( 100),

85
l.
:
float d[100];
int i,j,l;
1) ()
if (i<0 || i>l) printf("\n ");
else printf("d[%d]=%f ",i,d[i]);
2) , i-
if (i>=l) printf("\n ");
l--;
for (j=i+1;j<="1" i- 3)
d[j]="d[j+1];">=l) printf("\n ");
else printf("\n %d %d",d[i-1],d[i+1]);
4) new i-
if (i==l || i>l) printf("\n ");
else
{
for (j=l; j>i+1; j--) d[j+1]=d[j];
d[i+1]=new; l++;
}
5) 1,2,...,l
K1',K2',...,Ks,K1,Kt",...,Kt", s+t+1=l , K1'= K1.
{ int t=1;
float aux;
for (i=2; i<=l; i++)
if (d[i]=2; j--) d[j]=d[j-1];
t++;
d[i]=aux;
}
}

i,j,t aux=d[i]
.15.

.15.
.
Q, ,
: 1 2 - Q=1; 3,4 - Q=l;
5 - Q=l*l.
, 5 l,
3 4 ,
, - 1.
d
,
.

86
2.1.3.

nd, : val - , n , .
dl. :
typedef struct nd
{ float val;
struct nd * n;
int i,j;
ND * dl, * r, * p;

ND;

:
1) i-
r=dl;j=1;
while(r!=NULL && j++n ;
if (r==NULL) printf("\n %d ",i);
else printf("\n %d %f ",i,r->val);

2) (), p (. .16)

.16. .

if((r=p->n)==NULL) printf("\n ");


else printf("\n %f", r->val);
if(dl==p) printf("\n " );
else { r=dl;
while( r->n!=p ) r=r->n;
printf("\n %f", r->val);
}

3) , , (. .17)

.17. .

if ((r=p->n)==NULL) printf("\n
p->n=r->n; free(r->n);

");

4) new , (.
.18)

.18. .

r=malloc(1,sizeof(ND));
r->n=p->n;
r->val=new;

p->n=r;

5) , s+t+1=l,
K1'=K1; v K1' (. .19)

87

.19. .
ND *v;
float k1;
k1=dl->val;
r=dl;
while( r->n!=NULL )
{ v=r->n;
if (v->valn=v->n;
v->n=dl;
dl=v;
}
else r=v;
}

,
, : 1 2 - Q=l;
3 4 - Q=1; 5 - Q=l.
2.1.4.

,
( ).
:
typedef struct ndd
{ float val;
/*
*/
struct ndd * n; /*
*/
struct ndd * m; /* */
} NDD;
NDD * dl, * p, * r;

F=< 2,5,7,1 >


.20.

.20. .
new , p,
:
r=malloc(NDD);
r->val=new;
r->n=p->n;
(p->n)->m=r;
p->=r;

, , p
p->n=r;
p->n=(p->n)->n;
( (p->n)->n )->m=p;

88
free(r);

,
, dl - .
F=< 2,5,7,1 > .21.

.21. .
.
B1,B2,...,Bn 1
9999, Fi (1<I . Fn
.
Fi
Bi+1 Fi,
Fi+1. : ;
; .
,
<0,1000>.
, dl, r, p, v
: dl ; p, v - ; r
, in.
#include
#include
typedef struct str1
{ float val;
struct str1 *n; } ND;
main()
{ ND *arrange(void);
ND *p;
p=arrange();
while(p!=NULL)
{
printf("\n %f ",p->val);
p=p->n;
}
}
ND *arrange() /*
*/
{ ND *dl, *r, *p, *v;
float in=1;
char *is;
dl=malloc(sizeof(ND));
dl->val=0;
/*
*/
dl->n=r=malloc(sizeof(ND));
r->val=10000; r->n=NULL;
/* */
while(1)
{
scanf(" %s",is);
if(* is=='q') break;
in=atof(is);
r=malloc(sizeof(ND));
r->val=in;

89
p=dl;
v=p->n;
while(v->valn;
}
r->n=v;
p->n=r;
}
return(dl);
}

2.1.5.

,
.
- -
, , ,
. : S=
; ,
. ,
S=< >.
:
- S=< >,
- Sn+1 - < S1,...,Sn> <
S1,...,Sn+1>;
- - < S1,...,Sn-1,Sn> < S1,...,Sn-1>;
- Sn, .
, ,
. ,
.
- , ,
( ).
- ,
.
,
.

.
.
,
, ,
.

90
,
(6+8)*5-6/2


6 8 + 5 * 6 2 / -

,
, , .
,
, .

S = < >; <6>; <6,8>;
<70,6>; <70,6,2>;

<14>; <14,5>;
<70,3>; <67>.

<70>;

eval, ,
m , m[i]>0
, m[i]<0 - . ,
, -1, -2, -3, -4.
stack.
a l.
float eval (float *m, int l)
{ int p,n,i;
float stack[50],c;
for(i=0; i < l ;i++)
if ((n=m[i])<0)
{ c=st[p--];
switch(n)
{ case -1: stack[p]+=c;
case -2: stack[p]-=c;
case -3: stack[p]*=c;
case -4: stack[p]/=c;
}
}
else stack[++p]=n;
return(stack[p]);
}

break;
break;
break;

.
, , (..
"ABcEr-1." "1-rEcBA").
, ,
. -
, .
p q ,
STACK.
#include
typedef struct st
{ char ch;
struct st *ps;
main()
{
STACK *p,*q;
char a;

/* STACK */
} STACK;

91

p=NULL;
do
/*
{ a=getch();
q=malloc(sizeof(STR1));
q->ps=p; p=q;
q->ch=a;
} while(a!='.');
do
/*
{ p=q->ps;free(q);q=p;
printf("%c",p->ch);
} while(p->ps!=NULL);

*/

*/

2.1.6.

,
.
. B= V,
B'= B Ki Ki'=(i,Ki).
B"=< K1",K2",...,Km" > - B', Ki=(i,V).
", V
.
. , B=, ,
,
, .22,23.
1,C

3,Y

6,S

7,H

9,T

.22. .

.23. .
V
.
i-
, - .

.
.
M=< M1,M2,...,M10000 >, N=< N1,N2,...,N10000 >, 92%
.
Mi * Ni, i=1,2,...,10000.
, m
:
struct
{ int nm;
float val; }

m[10000];

92

m[j].nm=10001, (stopper)
m.
:
# include
main()
{ int i,j=0;
float inp,sum=0;
struct
{ int nm;
float val; }

/*
/*

*/
*/

m[10000];

for(i=0;i<10000;i++)
{ scanf("%f",&inp);
if (inp!=0)
{ m[j].nm=i;
m[j++].val=inp;
}
}
m[j].nm=10001;
for(i=0,j=0; i<10000; i++)
{ scanf("%f",&inp);
if(i==m[j].nm)
sum+=m[j++].val*inp;

/*

/*

stopper

/*

/*

*/

*/
N

*/
*/

}
printf( " Mi*Ni %f",sum);


. B = < K1,K2, ...,Kn >
1,2, ...,m ,
,
, 1,2, ...,m.
, B1,B2, ...,Bm
a X = < ADG1,ADG2,... ADGm >, ADGj - Bj,
j=1,M.
Bj j.
'
, j-
, ADGj,
Bj. ,
, j, Bj.
,
Pj Bj;
, , Bi,
i j Pj .
G(K),
j, .. G(K)=j. G , .K,
- .

93
B=< K1,K2, ...,K9 >
1=(17,Y),
K6=(77,T),

K2=(23,H),
K7=(50,U),

K3=(60,I),
K8=(88,W),

K4=(90,S),
K9=(30,S).

K5=(66,T),


Ga(K)=1+(.K-1)/3, :
B1a=<(17,Y),(23,H),(60,I)>,
B2a=<(90,S),(66,T),(77,T)>,
B3a=<(50,U),(88,W),(30,S)>.

, :
B1a'=<(1,17,Y),(2,23,H),(3,60,I)>,
B2a'=<(4,90,S),(5,66,T),(6,77,T)>,
B3a'=<(7,50,U),(8,88,W),(9,30,S)>.

Gb(K)=1+(.K-1)%3,
:
B1b"=<(1,17,Y),(4,90,S),(7,50,U)>,
B2b"=<(2,23,H),(5,66,T),(8,88,U)>,
B3b"=<(3,60,I),(6,77,T),(9,30,S)>.

K6
(). Ga(K) B2a',
Gb(K) B3b".
Gc(K)=1+K1/100, K1 - ,
:
B1=<(17,Y),(23,H),(60,I),(90,S)>,
B2=<(66,T),(77,T)>,
B3=<(50,U),(88,W)>,
B4=<(30,S)>.

- 1=77,
B2.

( Ga(X) ) C B1,B2,...,Bm (
Gc(Bi)), .. , , A-C .
- .
, ,
. B1,B2,...,Bm
, (). ,
, ,
- ,
, .
-
.24, X=.

94

.24. - .
.
, .
- ,
, , .
G(K)=K%100+1,
- 100 . :
#include
#include
typedef struct nd
{ float val;
struct nd *n; }
ND;
int index (ND *x[100])
{ ND *p;
int i,j=0;
float inp;
for (i=0; i<100; i++) x[i]=NULL;
scanf("%d",&inp);
while (inp!=0)
{
j++;
p=malloc(sizeof(ND));
i=inp%100+1;
p->val=inp;
p->n=x[i];
x[i]=p;
scanf("%d",&inp);
}
return j;
}

index .
. ,
, B=
K1=(338,Z),
K6=(334,Y),

K2=(145,A),
K7=(333,P),

K3=(136,H),
K8=(127,G),

K4=(214,I),
K9=(310,O),

K5 =(146,C),
K10=(322,X).

, .. X= ,
B1,B2,...,B7 ,
. , , Y=,
Y1,Y2,Y3 X,
. B1,B2,...,B7 ,

95
X,Y , B .
.25.

.25. - .

2.2.

.
. .
2.2.1.
: (
) =< K1, K2,..., Kn >. ,
B'=< K'1, K'2,...,K'n >, 1<=i<=n
K'(i) <= K'(i+1).
'
, ,
.


: .
:
B=<20,-5,10,8,7>,
B1=<-5,10,8,7,20>,
B2=<-5,8,7,10,20>,

;
;
;

96
B3=<-5,7,8,10,20>,

, (
n m) .
bubble
.
/*

float * bubble(float * a, int m, int n)


{
char is=1;
int i;
float c;
while(is)
{
is=0;
for (i=m+1; i<=n; i++)
if ( a[i] < a[i-1] )
{
c=a[i];
a[i]=a[i-1];
a[i-1]=c;
is=1;
}
}
return(a);
}

*/

Q=(n-m)*(n-m)
.
2.2.2.
B' :
1; i=2,...,N i B' , B'
i.
, B=< 20,-5,10,8,7 > :
B=<
B=<
B=<
B=<
B=<
B=<

20,-5,10,8,7>
-5,10,8,7 >
10,8,7 >
8,7 >
7 >
>

B'=<
B'=<
B'=<
B'=<
B'=<
B'=<

>
20 >
-5,20 >
-5,10,20 >
-5,8,10,20 >
-5,7,8,10,20 >

insert .
/*

float *insert(float *s, int m, int n)


{
int i,j,k;
float aux;
for (i=m+1; i<=n; i++)
{ aux=s[i];
for (k=m; k<=i && s[k]=k; j--)
s[k]=aux;
}
return(a);
}

*/

s[j+1]=s[j];

97
' s, s c
i n, B' - s c m i-1 (. .26).
Q=(n-m)*(n-m)
.

.26. .
2.2.3.
'
,
', .
:
B=<20,10,8,-5,7>,
B=<20,10,8,7>,
B=<20,10,8>,
B=<20,10>,
B=<20>,
B=< >,

B'=< >
B'=<-5>
B'=<-5,7>
B'=<-5,7,8>
B'=<-5,7,8,10>
B'=<-5,7,8,10,20> .

select s .
/*

double *select( double *s, int m, int n)
{
int i,j;
double c;
for (i=m; is[j])
{ c=s[i];
s[i]=s[j];
s[j]=c;
}
return(s);
}

*/

, '
s (. .27). Q=(n-m)*(n-m)
.

.27. .
. N
1,2,...,m, N, 1
G1.

98
Gj , Gj
Bj. ,
, , Q= N*N,
G.
2.2.4.
N
+N, . ,
=<6,17,23,39,47> =<19,25,38,60> 5 4
=<6,17,19,23,25,38,39,47,60> 9 .
,
,
.
,
s. s
: low
low+l, low+l+1 up, low, l, up
. merge
, low up (.
.28).
/*
*/
double *merge(double *s, int low, int up, int l)
{
double *b,*c,v;
int i,j,k;
b=calloc(l,sizeof(double));
c=calloc(up+1-l,sizeof(double));
for(i=low;is[up-1]) ?
(s[low+l-1]+1) : (s[up-1]+1)));
i=(j=0);
k=low;
while(b[i]<V||C[J]< } (s); return k++; s[k]="b[i++];" else if(b[i]

.28. .

2.2.5.
B'
= N 1=, B2=,...,Bn=,
1. , >=2
B1,B2,...,Bm /2 ( (+1)/2)
, B(2i-1)-o B(2i)- ( 2i<=M ) m
.
N.

99
,
, .
:
9 / 7 / 18 / 3 / 52 / 4 / 6 / 8 / 5 / 13 / 42 / 30 / 35 / 26;
7,9 / 3,18 / 4 / 52 / 6 / 8 / 54 / 13 / 30 / 42 / 26 / 35;
3,7,9,18 / 4,6,8,52 / 5,13,30,42 / 26,35;
3,4,6,7,8,9,18,52 /
5,13,26,30,35,42;
3,4,5,6,7,8,9,13,18,26,30,35,42,52.
, , Q=N*log2(N),
N ,

log2(N) .
N, .
smerge s ,
merge.
/* */
double *smerge (double *s, int m, int n)
{ int l,low,up;
double *merge (double *, int, int, int);
l=1;
while(l<=(n-m))
{ low=m;
up=m-1;
while (l+up < n)
{
up=(low+2*l-1 < n) ? (low+2*l-1) : n ;
merge (s,low,up,l);
low=up-1;
}
l*=2;
}
return(a);
}
.
srecmg .
,
, ,
.29.

.29. .
/*

1/2
double *srecmg (double *a, int m, int n)
{ double * merge (double *, int, int, int);
double * smerge (double *, int, int);
int i;
if (n>m)
{ i=(n+m)/2;
srecmg(a,m,i);
srecmg(a,i+1,n);
merge(a,m,n,(n-m)/2+1);
}
return (a);
}

*/

100
2.2.6.
, =< K1,K2,...,Kn>
B',< K1 >,B", ' - ,
1, " - , 1.
B',< K1 >,B" 1 ,
. B' "
.
, , Ki
< >.
:
9, 7, 18, 3, 52, 4, 6, 8, 5, 13, 42, 30, 35, 26
7, 3, 4, 6, 8, 5/ <9>/ 18, 52, 13, 42, 30, 35, 26
3, 4, 6, 5/<7>/ 8/ 9/ 13/ <18>/ 52, 42, 30, 35, 26
<3>/ 4, 6, 5/ 7/ 8/ 9/ 13/ 18/ 42, 30, 35, 26/ <52>
3/ <4>/ 6, 5/ 7/ 8/ 9/ 13/ 18/ 30, 35, 26/ <42>/ 52
3/ 4/ 5/ <6>/ 7/ 8/ 9/ 13/ 18/ 26/ <30>/ 35/ 42/ 52

. ,
B' " ,
N*log2(N) . ,

(N*N)/2 .
quick s
.
/*

*/
double * quick(double *s,int low,int hi)
{ double cnt,aux;
int i,j;
if (hi>low)
{ i=low;
j=hi;
cnt=s[i];
while(i < j)
{ if (s[i+1]<=cnt)
{ s[i]=s[i+1];
s[i+1]=cnt;
i++;
}
else
{ if (s[j]<=cnt)
{ aux=s[j];
s[j]=s[i+1];
s[i+1]=aux;
}
j--;
}
}
quick(s,low,i-1);
quick(s,i+1,hi);
}
return(s);
}
i j,
(. .30). i
cnt=s[low], , cnt, i
- , cnt. : s[i+1]<=cnt; s[i+1]>cnt
s[j]<=cnt; s[i+1]>cnt s[j]>cnt. i=j, cnt=s[i]
.

101

.30. .
log2(N)
quick ( ).
,
N ,
N , N!,
C(N),

. , C(N)/N! < 2*N*ln(N).


. ,
- D(j,n) - j-
n>=0, .. D(j,n)=floor(n/m)%10, m=10^(j-1).
0,1,...,9 - (), .
,
, j=1,2,...,T.
P , i (i=1,N)
Bm, m=D(j,Ki),
,
j- m.
0,1,...,9 ,
.
=2 :
B=<09,07,18,03,52,04,06,08,05,13,42,30,35,26> .
-1:
B0=<30>, B1=< >, B2=<52,42>, B3=<03,13>, B4=<04>,
B5=<05,35>, B6=<06,26>,B7=<07>, B8=<18,08>, B9=<09>.
-1:
B=<30,52,42,03,13,04,05,35,06,26,07,18,08,09>
-2:
B0=<03,04,05,06,07,08,09>, B1=<13,18>, B2=<26>,
B3=<30,35>, B4=<42>, B5=<52>, B6=< >,B7=< >,B8=< >, B9=< >.
-2:
B=<03,04,05,06,07,08,09,13,18,26,30,35,42,52>.
, N T- ,
Q(N*T).
.

, 0,1,...,9

, ,
.
pocket
( q),
- ,
; a[i], b[i]

Bi.
/*
e
*/
#include
#include
typedef struct str
{ long val;
struct str *n; } SP1;

102
main()
{ int i;
SP1 *q=malloc(sizeof(SP1)),*r;
SP1 *pocket(SP1 * ,int );
long a[14]={ 0,7,18,3,52,4,6,8,5,13,42,30,35,26
q->n=NULL;
q->val=a[0];
r=q;
printf(" %d",a[0]);
for(i=1;i<14;i++)
/*
{
r->n=malloc(sizeof(SP1));
r->val=a[i];
(r->n)->n=NULL;
r=r->n;
printf(" %d",a[i]);
}
r=pocket(q,2);
printf("\n");
/*
while (r!=NULL)
{
printf(" %d",r->val);
r=r->n;
}
}
/*

SP1 *pocket(SP1 *q,int t)
{ int i,j,k,m=1;
SP1 *r, *gg, *a[10], *b[10];
gg=q;
for(j=1;j<=t;j++)
{ for(i=0;i<=9;i++) a[i]=(b[i]=NULL);
while(q!=NULL)
{ k=((int)(q->val/m))%(int)10;
r=b[k];
if (a[k]==NULL) a[k]=q;
else r->n=q;
r=b[k]=q;
q=q->n;
r->n=NULL;
}
for(i=0;i<=9;i++)
if (a[i]!=NULL) break;
q=a[i];
r=b[i];
for(k=i+1;k<=9;k++)
if(a[k]!=NULL)
{ r->n=a[k];
r=b[k];
}
m=m*10;
}
return (gg);
}

};

*/

*/

*/

.31 - .

.31. .

103
.
, D(j,n) j-
n.
0 1;
, 0 1
. 0

1.
j- ,

.
.
B=
m=(MIN+MAX)/2.
1 2, 1 ,
m,
2 - , m. 1 2
.

2.3.1.
. : =<1,2,3,...,n>
V= ( ).
Vi V .
V ,
.
Max{}
Avg{} , V .
Pi - i , Si -
, ,
Max{} = max{ Si, i=1,n }

Avg{} =

Pi Si .

i=1


, V.
, ,
, , .
, Max N.
, .. P=1/N, Avg
N/2. Avg ,
.
100 1,2,... 100 V.
i ,

104
V, .
:
/*

#include
main()
{
int k[100],v,i;
for (i=0;i<100;i++)
scanf("%d",&k[i]);
scanf("%d",&v);
i=0;
while(k[i]!=v && i<100) i++;
if (k[i]==v) printf("%d %d",v,i);
else printf("%d ",v);
}

*/

:
/*
*/
#include
main()
{
int k[101],v,i;
for (i=0;i<100;i++)
scanf("%d",&k[i]);
/*

scanf("%d",&v);
k[100]=v;
/*

i=0;
while(k[i]!=v) i++;
if (i<100) printf ("%d %d",v,i);
else printf ("%d ",v);
}

*/
*/

2.3.2.

, .
, V .
, ,
.
. Max
log2(N), Avg
log2(N).
,
.
, , 101 , 1,2,...,100, V -
. , , V
.
V 1,2,...,100.
/*

#include
main()
{
int k[100],v,i,j,m;

*/

105
for (i=0;i<100;i++)
scanf("%d",&k[i]);
scanf("%d",&v);
i=0;
j=100;
m=50;
while (k[m]!=v)
{
if (k[m] < v) i+=m;
else j=m-i;
m=(i+j)/2;
}
printf("%d %d",v,m);
}

2.3.3. -
. ,
B N M B1,B2,...,Bm
N1,N2,...,Nm, , B=B1,B2,..,Bm.
V, Bi, i=1,M,
V,
Bi.
Bi .
M= N, Max - 2 N.
Avg - N.
, ,
, V. :
, .
V ,
- , ,
V.
2.3.4.
.
( ).
H(V), V -
[0,M-1], V T H(V) .. V=T(H(V)).

M.
T , H - .

V .
M .
M H .
K1,K2,..,Kn, , Ki=Kj,
mod(Ki,26)= mod(Kj,26). T(26)

106
0-25 H(V)= mod(V,26). T
T(H(Ki))=Ki T(j)=0 j (H(K1), H(K2),..,H(Kn)).
V T Z V T,
-1, V T,
int t[26],v,z,i;
i=(int)fmod((double)v,26.0);
if(t[i]==v) z=i;
else z=-1;

V Z ,
,
z=(int)fmod((doule)v,26.0);
t[z]=v;

V
t[(int)fmod((double)v,26)]=0;

, Ki=Kj H(Ki)=H(Kj)
. V - (
), 6. M=8
H(V)=Mod(V,8).
, B=, H(K1)=5, H(K2)=3, H(K3)=6, H(K4)=3, H(K5)=1, ..
H(K2)=H(K4) K2=K4. ,
.
.
T[8]
T=<0,K5,0,K2,K4,K1,K3,0> .

.
T[100], .. 0 99.
N 99, T
.
int static t[100];

T Z I
N :
i=h(z);
while (t[i]!=0 && t[i]!=z)
if (i==99) i=0;
else i++;
if (t[i]!=z) t[i]=z, n++;

T Z I Z, Z T, I=-1,
, :
i=h(z);
while (t[i]!=0 && t[i]!=z)

107
if (i==99) i=0;
else i++;
if (t[i]==0) i=-1;

,
.. t[i]=0, . , B K2,
T=<0,K5,0,0,K4,K1,K3,0>,
K4, H(K4)=3, T(3)=0.

.
,
.
, ,
, T
, T.
2.3.5.
. , B=,
, i-
. i=1 , i=2
.
j-
i=n-j+1 i- .
i=a/n, 0<a<1, ,
a=1/2.
, B ,
i- .
B ,
.

i- . , findi
/*
int findi(int *s, int n, int i)
{
int c,j,k;
for (k=0; k<=i; k++)
for (j=k+1; j<=n; j++)
if (s[k] < s[j])
{ c=s[k];
s[k]=s[j];
s[j]=c;
}
return s[i];
}

*/

i, s,
(n*i) . , findi
i, .

108
i- B
. B K1 B' B",
, Ki -B', Ki>K1, Ki - B", Ki<K1, B
B',K1,B". K1 j- j=i,
. j>i B'; j<i (ij) B".
,
,
. i-
B, .
1. N<21, i- B .
2. N>21 P=N/7 7 ,
mod(N,7) .
3. W (
) W M ( ) ..
(P/2+1)- .
4. M B B' j
M, B" c N-j M. j>i
, B'. j=i ,
M . j < i (i-j)-
B".
/*

*/
int search (int *b, int n, int i)
{
int findi(int *, int, int);
int t, m, j, p, s, *w;
if (n<21) return findi(b, n, i);
/*
1
*/
p=(int)(n/7);
w=calloc(p+1,sizeof(int));
/*
2 3
*/
for (t=0; t < p; t++)
w[t]=findi(b+7*t, 7, 3);
if (n%7!=0)
{
w[p]=findi(b+7*p,n%7,(n%7)/2);
p++;
}
m=search(w, p, p/2);
free (w);
for (j=0, t=0; t < n; t++)
/*
4
*/
if (b[t]>=m) j++;
if (j>i)
{
for (p=0, t=0; p < n; t++)
if (b[t]>=m)
{ b[p]=b[t]; p++; }
m=search(b, j, i);
/*
B"
*/
}
if (j < i)
{
for (p=0, t=0; t < n; t++)
if (b[t] < m)
b[p++]=b[t];
m=search(b, n-j, i-j);
/*
B"
*/
}

109
return m;

search i- .

#include
#include
main()
{
int search (int *b, int n, int i);
int *b;
int l, i, k, t;
scanf("%d%d",&l,&i);
printf
("\n %d %d ",i,l);
b=(int *)(calloc(100,sizeof(int)));
for (k=0; k<100; k++)
b[k]=k;
/*
for (k=1; k < l/4; k++)
{ t=b[k];
/*
b[k]=b[l-k];
/*
b[l-k]=t;
}
k=search(b,l,i);
/*
printf ("\n %d\n\n",k);
return 0;
}

*/
*/
*/
*/

, , search
28*N .
, N<21, findi
N*(N-1)/2, .. 28*N. , T<N
search 28*T ,
search N.
findi 7*(7-1)/2=21
, W 21*(N/7)=3*N .
W N/7
28*(N/7)=4*N . B B'
( B") N*5/7 ,
N. (
B' B") 28*(N*5/7)=20*N .
, 3*N+4*N+N+20*N=28*N , ..
.

2.4.
,
, , , .
()
.

110
int a()
{.....a().....}

,
. , ,
.
:
a(){.....b().....}
b(){.....c().....}
c(){.....a().....} .

a,b,c , ,
.
. 1,2,3.
1 n ,
(..31).
, 1 3
2 .
,
. , n
2^n-1.

.31. .
, ,
- i j,
( i -> j). ,
n i j, w
. n-1 i w
j, i j ,
, n-1 w j, i.
, n n-1
. : T(n,i,j,w) = T(n-1,i,w,j),
T(1,i,j,w), T(n-1,w,j,i).
n-1
w
n-1
j
-------->-+|+--------->+ |
I
|||

| |
/ \
/ \
/ \
+-/-----\-+
/
\
+-/-----\-+
==+----|----+===/=========\====+----|----+======
+-------------->-------------+

.32. .

+
n-1|
+

i
|
|

, n ,
n.

111
tn(n,i,j,w), ,
n i j
w {i,j,w} = {1,3,2}.
/*

#include
main()
{
void tn(int, int, int, int);
int n;
scanf(" %d",&n);
tn(n,1,2,3);
}
void tn(int n, int i, int j, int w)
{ if (n>1)
{ tn (n-1,i,w,j);
tn (1,i,j,w);
tn (n-1,w,j,i);
}
else printf(" \n %d -> %d",i,j);
return ;
}

*/
/*
/*

*/
*/

/*
/*

*/
*/

tn m=3
.33. tn n, i, j, w
. tn ,
n, i, j, w, ,
n, i, j, w ,
.

.33. tn.

,
.
, :
main()
{ ... f() ...}
f()
{ ... f() ...}

/*

*/

/*

*/

main f.
f , .. f.

112
f 1,2,...,s,
V1,V2,...,Vt main f k f.
:
- AR1,AR2,...,ARs,
f ( 1,2,...,s);
- rz f (
f);
- , f,
lr int, , pst ,
;
- dl ;
- u ;
- k L1,...,Lk ;
- jf, f;
- l int .
f,
:
1. f main;
2. main AR1,AR2,...,ARs,RZ,
ST dl u:
typedef struct st { P1;P2;...;Ps;V1;V2;...;Vt;
int lr; struct st *pst }
ST *dl=NULL, *u;

ST;

3. f . :
) f;
) :
goto jf;
f: a=malloc(sizeof(ST));
a->P1=AR1; a->P2=AR2; ... ;a->Ps=ARs;
a->lr=l; a->pst=dl; dl=a;

) f JF,
, ;
) return(y) f :
RZ=y; l=dl->lr;
a=dl; dl=a->pst; free(a);

113
switch(l)
{ case 1: goto L1;
case 2: goto L2;
...
case k: goto Lk;
}

4. i- f ( , f)
V=f(A1,A2,...,As) :
AR1=A1; AR2=A2; ... ; ARs=As;
Li: V=RZ;

l=i;

goto f;

l=i l=1 f, l=2


..
switch goto Li; ( Li L1
, Li L2 ..)
5. f main.

, :
+
|
|
A(N,X,Y)= |
|
+

X+1,
X,
0,
1,
2,
A(N-1,A(N,X,Y-1),X),

N=0
N=1,
N=2,
N=3,
N=>4,
N#0,

Y=0,
Y=0,
Y=0,
Y=0,
Y#0;

N,X,Y - .


ackr smacc:
/*

*/
# include
main ()
/*
*/
{
int x,y,n,t;
/*
*/
int ackr(int, int, int);
scanf("%d %d %d",&n,&x,&y);
t=ackr(n,x,y);
printf("%d",t);
}
int smacc( int n,int x )
/* */
{
switch (n)
/*

*/
{ case 0: return(x+1);
case 1: return (x);
case 2: return (0);
case 3: return (1);
default: return (2);
}
}
int ackr( int n, int x, int y)
/*
*/
{ int z;
/*
*/
int smacc( int,int);
if(n==0 || y==0) z=smacc(n,x);
else { z=ackr(n,x,y-1);
/*
*/
z=ackr(n-1,z,x); }
/* ackr(...) */

114
}

return z;

main ackr
:
/*

/*

#include
#include
int main()
{ typedef struct st
{ int i,j,k,z,lr;
struct st *pst;
} ST;
ST *u, *dl=NULL;
int l,x,y,n;
int smacc(int,int);
int an,ax,ay,rz,t;
scanf("%i %i %i",&n,&x,&y);
an=n;ax=x;ay=y;l=1;
goto ackr;
l1: t=rz;

/*
/*
/*

*/
*/


t=ackr(n,x,y);
- - - - - -

*/
*/
*/

printf("\n %d ",t);
goto jackr;
/*
ackr
ackr:
u=( ST *) malloc( sizeof (ST) );
u->i=an;
u->j=ax;
u->k=ay;
u->lr=l;
u->pst=dl;
dl=u;
if (an==0||ay==0)
dl->z=smacc(an,ax);
else
{
an=dl->i;
/*
ax=dl->j;
/*
ay=dl->k-1;
/*
z=ackr(n,x,y-1);
l=2;
/*
goto ackr;
/*
l2: dl->z=rz;
/* - - - - - - an=dl->i-1;
ax=rz;
ay=dl->j;
l=3;
goto ackr;
dl->z=rz;

l3:
}
rz=dl->z;
an=dl->i;
ax=dl->j;
ay=dl->k;
l=dl->lr;
u=dl;
dl=u->pst;
free(u);

*/

/*
/*
/*
/*
/*
/*

/*
/*
/*
/*
/*
/*
/*
/*

z=ackr(n-1,z,x);

return z ;

*/
*/
*/
*/
*/
*/
*/
*/
*/
*/
*/
*/
*/
*/
*/
*/
*/
*/
*/
*/

115
switch(l)
/*
{ case 1: goto l1; /*
case 2: goto l2; /*
case 3: goto l3; /*
}
/* - - - - - - - jackr:
}
int smacc( int n,int x )
/*
{ switch (n)
{ case 0: return(x+1);
case 1: return (x);
case 2: return (0);
case 3: return (1);
default: return (2);
}
}

*/
*/
*/
*/
*/
*/