You are on page 1of 26

1.

:
;
;
.
:
program<????????????>;
() 8
( , , ).
.
, , ,
, , .
,
. :
( label);
( const);
( type);
( var);
( function
procedure);
begin
, .
end .

2.
.
:
integer. 32768
32767.
real. () 2,9 10 39
1,7 10 38 .
char. ( , , ,
), .
boolean. . : true ()
false ().
,
. (
1

, ,
, ).
. :
vari,j:integer;x,y:real;
(i, j , x, y ).

3. .
.
( :=) :
<?????????????>:=<????????>
:= ,
.
, .
:

+,,*
+,,*
/
div,mod
and,or,not
>,>=,<,<=,=,<>


integer
real
integer,real
integer
boolean
integer,real,
char,boolean


integer
real
real
integer
boolean
boolean

.
.
( ):
1. not;
2. *, /, div, mod, and;
3. +, , or;
4. >, >=, <, <=, =, <>.
,
, . ,
, .
()
:

abs(x)
abs(x)
sqr(x)
sqr(x)
sqrt(x)
sin(x)
cos(x)


integer
real
integer
real
real
real
real


integer
real
integer
real
real
real
real
2

x
x

x2
x2
x

sin x
cos x

arctan(x)
exp(x)
ln(x)
odd(x)
round(x)

real
real
real
integer
real

real
real
real
boolean
integer

trunc(x)

real

integer

ord(a)

integer

integer
char

chr(n)
succ(a)
pred(a)

arctg x
ex

ln x

4. .
,
.
:
) :
if < > then <.1> else <.2>;
) : if <> then <.1>;
<> - ,
<.1> <.2> - .
:
) : <>.
(true), <.1>, (false),
<.2>.

-:

<>

<. 2>

<. 1>

) : <>. ,
<.1>. , .
:

<>

<. 1>

1. <. 1> <. 2>


. ( )
,
( )
begin end:
begin
< ,
>
end;
2: <.1> <.2>
. else
then.
. D (. ).
1

D
-1

x y,
. u v :u=1, v=0,
(x,y) D;u=0, v=1, (x,y) D.

.
D. D D1 D2,
D=D1D2.
D1

D2

-1

(x,y) D (x,y)
D1 (x,y) D2, (x,y) D1 :
1) (x,y) 1;
2) (x,y) Y;
3) (x,y) X.
:
x2 y2 1

x0

y0

:
(x*x+y*y<=1) and (x<=0) and (y>=0).
, (x,y) D2 , :
1) (x,y) D2;
2) (x,y) Y;
3) (x,y) X,

y 1 x

x0

y0

:
(y<=1-x) and (x>=0) and (y>=0)
, (x,y) D :
((x*x+y*y<=1)and(x<=0)and(y>=0))or
((y<=1-x)and(x>=0)and(y>=0))
:
program pr1;
var x,y:real;
u,v:integer;
begin
writeln( x,y);
read(x,y);
if ((x*x+y*y<=1) and (x<=0) and (y>=0)) or
((y<=1-x) and (x>=0) and (y>=0)) then
begin
6

u:=1;
v:=0
end else
begin
u:=0;
v:=1
end;
writeln(u=,u,_v=,v)
end.

5.
,
.
.
1. ( FOR)
:
for <.>:=<n1> to <n2> do <.> ;
:
<.> , - ,
integer,
<n1> , ,
,
<n2> , ,
<.> , ,
, , <n2>.
, for :
<n1> <.>:=<n1>.
( ):
1) <.><n2>+1, (..
<.>=<n2>+1) , ;
2) <.>;
3) <.> .
1: <.>, <n1> <n2>
real, -.
2: <.> .
, ,
begin end.
-: FOR:

<.>:=<n1>

<.><n2>+1

<.>

<.>= <.>+1

FOR:
for <.>:=<n2> downto <n1> do <.> ;
<.>
. <.>=<n1>1.

-:

<.>:=<n2>

<.><n1>1

<.>

<.>= <.>1

2. ( WHILE)
:
while <> do <.> end;
:
<> ,
<.> .
. :
1) <>. false (.. <>
), ;
2) , <> , <.>.
-:

<>

<.>

: FOR, <.>
. , , ,
begin
end.
3. ( REPEAT)
:
repeat
<.1>;
<.2>;

<.N>;
until <>;
:
<.1>, <.2> ,, <.N> ,
<> - .
. <.1>, <.2> ,, <.N>
, <>.
true, .
, <.2> ,, <.N> ,
.
-:

<.1>

<.2>

<.1>

<>

1. repeat until
, ( FOR WHILE)
.
10

2. <> WHILE <> REPEAT


: WHILE <>
, REPEAT <> .
1. n.
n
k

3
k 1 1 k
. s,
0. , s
. k ( 0
n), FOR k
1 n.
:
program pr2;
var k,n:integer; s:real;
begin
writeln( n);
readln(n);
s:=0;
for k:=1 to n do
s:=s+k/(1+k*k*k);
writeln(s=,s)
end.
2. , 1, n
( ). ,
.
. ,
, .
, REPEAT.
.
:
program pr3;
var k,eps,s,a:real;
begin
writeln( eps);
read(eps);
s:=0;
k:=1;
a:=0.5;
repeat
s:=s+a;
k:=k+1;
a:=k/(1+k*k*k)
until abs(a)<eps;
writeln(s=,s)
end.
11

3. n, m.

i
i 2 j 1

1
j3

. ,
. j
i, i.
:
program pr4;
var i,j,m,n:integer;
s:real;
begin
writeln( m,n);
read(m,n);
s:=0;
for i:=2 to m do
for j:=1 to n do s:=s+1/(i*i+j*j*j);
writeln(s=,s)
end.
4. ,n.
( 1) k x k

k!
k 1
n

:
k!=1*2*3**k, , x k ,
,
1 k
1 k

( 1 ) k

,
, x k exp(k*ln(x)),
,
, (1) k.
, .
.
,
( ).

.
.
(1) k x k
k- ak , ak
.
k!

, ak 1 ak .
ak 1 ( ak k+1 k):
ak 1

( 1) k 1 x k 1
( k 1)!

12

ak 1 ak :
a k 1 ( 1 )k 1 x k 1
k!
k!
1* 2 * ...* k
x

x
x

k
k
ak
( k 1 )! ( 1 ) x
( k 1 )!
1* 2 * ...* k * ( k 1 )
k 1
a x
, ak 1 k .
k 1

.
ak , , a1 :
a1 =.
, a1 , ,
a2 ; a2 , a3 .

s ak.
program pr5;
var s,x,a:real;
k,n:integer;
begin
writeln( x,n);
readln(x,n);
s=0;
a:=-x;
for k:=1 to n do
begin
s:=s+a;
a:=-a*x/(k+1);
end;
writeln(s=,s)
end.

, .
5.
( 1 )k x k cos kx

k!
k 1
n

4
.
.,

ak

( 1 )k x k cos kx
,
k!

, .
, ,
, .
a k

( 1 )k x k
. , s
k!

13

s:=0;
a:=-x;
for k:=1 to n do
begin
s:=s+a*cos(k*x);
a:=-a*x/(k+1);
end;

6.

( ), .
().
.
- , integer.
real, -.
, ,
array (. ).
.
.
- .
1 . :
type < >=array[< >] of < >;
< >
.
< >:
var < >: < >;
, a 10 (..
a1, a2, , a10 :
type mass=array[1..10] of real;
var a:mass;
2 .
:
var < >:array[< >] of < >;

var a:array[1..10] of real;
.
. 10
:
var a:array[0..9] of real;

var a:array[-4..5] of real;


, a 10 ,
0 9 4 5
.
14

-
, , i-
a (ai) a[i].
.
( ) .
1. :
var a:array[1..10] of real;
k:integer;
. . . . . . . . . . . .
writeln( 10 );
for k:=1 to 10 do read(a[k]);
2. :
var a:array[1..10] of real;
k:integer;
. . . . . . . . . . . .
for k:=1 to 10 do
begin
writeln( a[,k,]);
read(a[k]);
end;
.

,
.
( ) .
( ).
:
type mass=array[1..20] of real;
var a:mass; n,k:integer;
. . . . . . . . . . . .
repeat
writeln( n<=20);
read(n)
until n<=20;
writeln( ,n, );
for k:=1 to n do read(a[k]);
n, (.. 20) repeat
n<=20.
.
1. :
for k:=1 to n do write(a[k]);
, , write(a[k]:5:1),
.
15

2. :
for k:=1 to n do writeln(a[k]);
2a. :
for k:=1 to n do writeln(a[,k,]=a[k]);
. n, a n .
: , .
. :
program pr6;
type mass=array[1..50] of integer;
var a:mass; k,n:integer;
begin
repeat
writeln( n<=50);
read(n)
until n<=50;
for k:=1 to n do
begin
writeln( a[,k,]);
read(a[k]);
if a[k]>0 then a[k]:=2*a[k] else a[k]:=0
end;
writeln ( );
for k:=1 to n do writeln(a[,k,]=a[k]);
end.

7. ( )
() ,
(,
). .
,
,
: ,
.
,
(,
real). , :
, (
).
.

16

, .
, 1020 (10 , 20 )
:
:
type matr=array[1..10] of array[1..20] of real;
var a:matr;
:
var a:array[1..10] of array[1..20] of real;
:
:
type matr=array[1..10,1..20] of real;
var a:matr;
:
var a:array[1..10,1..20] of real;

:
a[i][j] a[i,j]
.
.
a(1020).
1) :
for i:=1 to 10 do
for j:=1 to 20 do
begin
writeln( a[,i,,,j,]);
read(a[i,j])
end;
2) :
for i:=1 to 10 do
begin
writeln( ,i, 20 );
for j:=1 to 20 do read(a[i,j])
end;
3) :
for j:=1 to 20 do
begin
writeln( ,j, 10 );
for i:=1 to 10 do read(a[i,j])
end;
4) :
writeln( 10*20);
for i:=1 to 10 do
17

for j:=1 to 20 do read(a[i,j])


. , ( )
, ,
( ).
.


. , :
for i:=1 to 10 do
begin
for j:=1 to 20 do write(a[i,j]:5:1);
writeln
end;
. n, a(nn).
: ,
.
.
i , j .
i=j.
a11 a12 a13 ... a1n

()
a 21 a 22 a 23 ... a 2 n
:
a
a 32 a 33 ... a 3 n
31

( i 2 n),
...
...
... ... ...

j i (.. i-

a n1 a n 2 a n 3 ... a nn
) j=1,
, .. j=i1.
.
program pr7;
type matr=array[1..20,1..20] of real;
var a:matr;
i,j,n:integer ;
s:real;
begin
repeat
writeln( n<=20);
read(n)
until n<=20;
for i:=1 to 20 do
begin
writeln( ,i, ,n, );
read(a[i,j])
end;
s:=0;
for i:=2 to n do
for j:=1 to i-1 do s:=s+a[i,j];
for i:=1 to n do a[i,i]:=s;
for i:=1 to n do
18

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

8.

.
:
type < >=file of < >;
, .

(
).
( )
.

( :
).

assign:
assign(<..>,< >);
:
<..> ,
< > , .
,
.

reset:
reset(<..>);
,
.

rewrite(<..>);
, <..> .
,
, .

append(<..>);
.
. append

19

, .. ,
text (. ).
.
.
, .
,
text.
read, readln (
) write, writeln ( ).
.
read , . :
read(<..>,< >);
, <..>
() .
read , ,
.
read
.
readln(<..>,< > read
,
, ,
read readln .
write(<..>,< >)
, <..>,
.
writeln(<..>,< >) write
,
, , write writeln
.


close(<..>);
, !
-
() , , .
. a(mn) b(nk)

4

a 7
5

0
2
7

1
4
3

4 , b 4 7

9
1
7

. c . c mk,

n

cij ail blj ,

i 1,..., m , j 1,..., k

l 1

20

pr8.pas,
pr8.dat, pr8.res.
.
program pr8;
type matr=array[1..20,1..20] of real;
var a,b,c:matr;
i,j,k,l,m,n:intrger;
fd,fr:text;
begin
assign(fd,pr8.dat);
assign(fr,pr8.res);
reset(fd);
rewrite(fr);
read(fd,m,n,k);
for i:=1 to m do
for j:=1 to n do read(fd,a[i,j]);
for i:=1 to n do
for j:=1 to k do read(fd,b[i,j]);
for i:=1 to m do
for j:=1 to k do
begin
c[i,j]:=0;
for l:=1 to n do c[i,j]:=c[i,j]+a[i,l]*b[l,j]
end;
writeln(fr, a b);
for i:=1 to m do
begin
for j:=1 to k do write(fr,c[i,j]:5:1);
writeln(fr)
end;
close(fr)
end.

pr8.dat : m, n, k,
a b.
:
3 3 2
4 0 1
7 2 4
5 7 9
-3 4
-4 7
1 7

9. .
21

,
, , .
.
:
type <>=record
< >
end;
< >
:
< 1>:< 1>;
< 2>:< 2>;

< N>:< N>


birthday (
), day, month year (,
).
type birthday=record
day:1..31;
month:1..12;
year:integer
end;
var a,b:birthday;
a, b birthday.
,
,
a.day:=7;
b.year:=1993;

( ),
var c:record
name:string;
bd:birthday
end;
year :
c.bd.year:=1993;

:
with< > do <>;

, ,
c.bd.day:=14;

with c.bd do day:=14;

22

with c do with bd do day:=14;

with c,bd do day:=14;


. (, , ) .
, .
. : bd ( ) d ( ).
z ,
( ) ;
.
.
program pr9;
type dat=record
day:1..31;
month:1..12;
year:integer;
end;
var bd,d:dat; z:integer;
begin
writeln( );
with bd do
begin
write(:_);
read(day);
write(_:_);
read(month);
write(_:_);
read(year);
end;
writeln( );
with d do
begin
write(:_);
read(day);
write(_:_);
read(month);
write(_:_);
read(year);
end;
if (d.month>bd.month)or
(d.month=bd.month)and(d.day>=bd.day)
then z:=d.year-bd.year
else z:=d.year-bd.year-1;
writeln( :_,z)
end.

23

10.
( )
,

.
:
function < >(<
>):< >;
,
(
) . (
) ( ,
). -
(, ..),
, type.
,
, .. .
,
.
. (
! , ..)


(), , ..
,

.
. x, y.
w

f ( x 2 , y ,10 ) f ( 1, x y ,15 )
,
1 f ( y 3 ,cos x ,20 )

f ( x , y ,n )

1
1 y

kx

sin 10
k 1

. f
x, y n.
k s.
.
.
program pr10;
var x,y,w:real;
function f(x,y:real;n:integer):real;
var k:integer; s:real;
begin
24

s:=0;
for k:=1 to n do s:=s+sin(k*x/10);
f:=s/sqrt(1+y*y)
end;
BEGIN
writeln( x,y);
read(x,y);
w:=(f(x*x,y,10)-f(1,x-y,15))/(1+f(y*y*y,cos(x),20));
writeln(w=,w)
END.
:
procedure < >(<
>);

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

( ,
/), -
. , (.. ,
) , ..
- ( var ).
- ,
- ,
, .
,
,
:
< >(< >);
,
.
,
,
, , (
,
, ).

25

. 22.
.
. prod -:
a, b c, a b.
b, a,
r, a.
.
.
program pr11;
type matr=array[1..2,1..2]of real;
var a,b,r:matr;
i,j:integer;
fd,fr:text;
procedure prod(a,b:matr;var c:matr);
begin
c[1,1]:=a[1,1]*b[1,1]+a[1,2]*b[2,1];
c[1,2]:=a[1,1]*b[1,2]+a[1,2]*b[2,2];
c[2,1]:=a[2,1]*b[1,1]+a[2,2]*b[2,1];
c[2,2]:=a[2,1]*b[1,2]+a[2,2]*b[2,2];
end;
BEGIN
assign(fd,pr11.dat);
assign(fr,pr11.res);
reset(fd);
rewrite(fr);
for i:=1 to 2 do
for j:=1 to 2 do read(fd,a[i,]]);
prod(a,a,r);
prod(a,r,b);
for i:=1 to 2 do
begin
for j:=1 to 2 do write(fr,b[i,j]:5:1);
writeln(fr)
end;
close(fr)
END.
. b
: prod ,
-.
( ,
- ).

26