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

1

Pascal



:
- 26
-
- 32
- + - * / : , < > = . ; () [] {}

-
.


. A B.

:
pr1
A,B,P
A,B

:
Program pr1;
var A,B,P: integer; { }
Begin

P:=(A+B)*2

Read (A,B);

{ A B}

,P

P:=(A+B)*2;

{ }

Writeln(P);

{ }

End.
Program..
. Var A,B,P ,
- (integer). Begin End


- , , .
. .
- ,
. Program, Var, Begin, End.
, .
() - .
: .
(,
, ). ,
-, Read, Writeln.

.
.
P. P1, Perim.

.
. .

. ,
. A B

.

, ..
. 2.
.
.
.
{}

.
, :
PROGRAM ;

BEGIN

END.

PROGRAM, , .
; .

( , , .).
: , , , , .
. ,
. , ,
: . ; .
: BEGIN () END (),
END .
. ; .


:
PROGRAM ;
LABEL

- ;

CONST

- ;

TYPE

- ;

VAR

- ;

PROCEDURE

- ;

FANCTION

- ;

BEGIN
1;
2;
...
n-1;
n;
END.

.
V (3 / 4) R 2
{ }
PROGRAM PR1;
CONST PI=3.14;
VAR

R:REAL; { }
V: REAL; { }

BEGIN
R:=0.2;
V:=4*PI*R*R*R/3;
WRITELN( =,V:8:3)
END.

, R=0,2 -

: ; ;
, BEGIN - END.
.
=3.14,
.
, R
V, (REAL), ..
.
R V.

R:=0.2;
V:=4*PI*R*R*R/3;
V .

WRITELN( =,V:8:3)

V 8:3 ( 8 -
; 3 - ).
,
= 0.033



. , , ,
, , ,
. .
- .
INTEGER, REAL, BOOLEAN CHAR
. .
.
(,
, ).
, .
.
.
.
( ) - , .
, -, ,
+ .
. ,
- , , (,
), .. :
14, -357, 0, 5390.


.
-32768 +32767.
, ,
( INTEGER).
, : + (), - (), *
(), DIV - (
), MOD - .
, , A, B, N - , : A=25, B=2, N= -17.
:
A+51
( 76)
B-A
( -23)
B*N
( -34)
A DIV B
( 12)
A MOD B
( 1)

MOD , X 2,
.. X .
X MOD 2 . , X - ,
, . , - ,
..

.
:
.


, . ,
27.3, 5.0, -16.003, 200.59.

. , 680 000 000 68107 (7 - ),
0,00000005 5 108 (-8 - ).

.
mEp. m - ; E - ; p - .
m . p
. + -.
,
.
:

0,62 10 4

4E 5
0.62 E 4

10 ,88 10 12

10 .88 E12

4 10 5


, . ,
, :
0.547E+3, 5.47+2, 54.7+1, 547.0-1, 54700-2
547.
( ) ,
.
, , ( 0) 1038
,
1038.
,

. , 0.517
0.516999.
(REAL) - ,
.
,
: + (); - (); * (; / ().

.
. ,
- .
: TRUE () FILSE ().
BOOLEAN.

. .
: < (); <=
( ); = (); <> ( ); >= ( ); > ().
,
: . , 5>3 ( ?)
(TRUE); 5=3 ( ?)
(FALSE).
: OR -
(); AND - (); NOT - ().
OR AND , NOT - .
,
( ) . ( ) ,
.
,
. , .
,
, .
, FALSE < TRUE.

.
:

NOT A

A OR B

A AND B

TRUE

TRUE

FALSE

TRUE

TRUE

TRUE
FALSE
FALSE

FALSE
TRUE
FALSE

FALSE
TRUE
TRUE

TRUE
TRUE
FALSE

FALSE
FALSE
FALSE

, (C>10) OR (D<3)
: ) =12 D=2; ) C=12 D=5; ) C=8 D=2;
C=12 D=5.
(>10) AND (D<3) C=12 D=2;
: ) C=12 D=5; ) C=8 D=5; ) C=8 D=2.

,
.
: 1 - , 0 - .



, ,
,
. ,
, , ..
, ,
. , A, +, 9, :.
,
: . , ,
.
( CHAR) - ,
. ,
, ,
A > B.


.

. ,
. CONST
: CONST = ;
, CONST N = 18;
.
, :
CONST
NUM = 23;

{ }

B = 1.8E-3;

{ }

PI = 3.14;

{ }

SIM = R;
L = TRUE;

{ }
{ }



, ,
.
VAR :
VAR : ;
, :
VAR
B : INTEGER; { }
SUM : REAL;
{ }
K : CHAR;
{ }
LOG : BOOLEAN; { }
,
. ( ), . :
VAR
R, V : REAL;
K, L, TOR : INTEGER;
R, V - ; K, L, TOR -
.


, , , , ,
, .
,
, . ,
, .
:
1. .

2. ,

.
,
. X
, X/180.


:
SQRT(X) - X,
X ;
SQR(X) - X, X 2
SIN(X) - X, sin x.
ABS(X) - () X,
X ;
ORD(X) - X, ,
ORD(R) 82 (
R).
CHR(X) - , X, ,
CHR(68) D ( D
68 ).
PRED(X) - X, ,
PRED(N) M.
SUCC(X) - X, ,
SUCC(S) T.
PRED(X) SUCC(X) ,
X ,

.
,
.

.
, ,
. :
A+B*T1/T2 - 2.3*SQRT(X).
, .
, .

.
. , A+N
A*2, A -
, N - .
:
1. .
. ,
a1 x1 b2 x2 5a3 x3
25 d 14 f

:
(A1*X1+B2*X2+5*A3*X3)/(25*D-14*F).

.
2. - .
,
.
a{b+c[d+e(f+g)]}

a*(b+c*(d+e*(f+g))).

.
, .
3. . ,
3*A*B/-Z . : 3*A*B(-Z).
4. ,
.
, , SIN(X).
, DIV MOD.

.
,
. ,
SIN(0.14+Z)
(0.14+Z), SIN.

.
,
.
, .
TRUE FALSE.
:
1)
2)
3)
4)

NOT
*, /, DIV, MOD, AND;
+, -, OR;
<, <=, =, < >, >=, >;

, , .
.
(
), .
, AND OR.

.
.
(a > 3) AND (b=a+6) OR NOT (c=4)
a=2, b=8, c=5.
:
) a > 3 . - FALSE,
2 < 3;
) -
a+6, b a+6. TRUE, 8=8;
) c=4 . - FALSE,
5
4;
) NOT(c=4), NOT FALSE. - TRUE;
) AND (FALSE AND TRUE).
- FALSE;
) OR (FALSE OR TRUE).
- TRUE.
! .
x
. , a
EXP(x*LN(a));
EXP LN - ( ).


.
. ()
, .
: , , ,
; ,
, , .
.
V:=A
V ; := ; A .
A,
:= , V, .
:=
= . ,
. , X=X+2
. X:=X+2
: X (
5) 2,
X 7.

, . :
T := 527.475;
M := TEMP;
Y := SQRT(X);


,
. , L, M N ,
L:=M AND N.
, M
TRUE, N
FALSE, L
FALSE.
,
. ,
D
VAR
D : REAL;
D := F; ,
. ,
.

VAR A,B,C,D : REAL;

A:= (B<C) AND (D>C);

, A
.


.

.
. , , A B ,
A=6, B=5. C .

C := A*B
A*B, 30,
30.0

:
Y := A+ROUND(B/3)*2;
SUM := SUM+X;
C5 := 2*K-SIN(PI/4-X);

.
.
.
:
BEGIN
1;
2;

n-1;
n;
END
BEGIN () END ()
. BEGIN , END
.
.
, .
, , .
BEGIN END ;
.

.
.
, .
,
- . :
A := B;
R := 2;
;
K := 7.2;
.
.
, ?
, .
, :
A, B, C, D
,

(A, B, C, D)
- :
.

.
.
,
, :
((A, B, C, D), (K, L, M), E, (R, S))
,
BEGIN END, ,
.
.

:
BEGIN
BEGIN
A;
B;
C;
D
END;
BEGIN
K;
L;
M
END;
E;
BEGIN
R;
S
END
END


; .


.
, :
A := 5;
BB := -6.143;
,
.
READ.
READ,
. ,
.
READ ( a1 , a2 ,..., an )
a1, a 2 ,..., a n , .
:
.
A, B, C
: A=5, B=17, C=6.2.
READ (A, B,C)
a :
5
17
6.2


, ,
:
16
-4
-0.5

A=16, B= -4, C= -0.5,
. .

READLN,
.

READLN ( a1 , a2 ,..., )an
a1 , a2 ,..., an ,
. .
.
WRITE.
WRITE ( a1 , a2 ,..., an)
a1 , a2 ,..., an ,

, .
,
WRITE ( B= , B)

B=
B.



WRITE. .
.
, .
,
, ., Y
WRITE (Y:5:2) , Y
, . ,
Y 1.76,

1
.
76

, , ,
,
.
Y=1.76
WRITE (Y= , Y:8:3)
:

Y
1.
760


.
N=179.
WRITE (N= , N:5)
. 3,

WRITE (N= , N:5)

N 179

N -179

.
WRITELN .
.
.
WRITELN (a1, a2 ,..., an )
a1, a2 ,..., an , . ,

WRITE( a1, a2 ,..., an); WRITELN


.
WRITE.
. , A, B, C

WRITE ( a, b, c);
READ (a, b, c);
, a, b, c
a, b, c
, : 5176.2
, ,
.
.

1. V R

V (4 / 3)R 3 .

,
. R:=0.2,
READ (R), R
. , R V
38.
10
PROGRAM Pr1;
{ }

CONST PI=3.14;
:
VAR R, V : REAL;
BEGIN
R:
WRITELN ( R:);
0.2
READ (R);
V:= 4*PI*R*R*R/3;

WRITELN;
= 0.033
WRITELN ();
WRITELN ( = , V:8:3);
readln
END.

2. , .

B
E

C
F

S. , S=EFH, EF=(BC+AD)/2
, ; H .
.
PROGRAM PR2;
{ }
VAR
BC, AD, H : REAL; { }
S : REAL; { ()}
EF : REAL; { ( )}
BEGIN

WRITELN ( BC, AD, H:);

READ (BC, AD, H);
BC, AD, H:
EF := (BC+AD)/2; { }
S:=EF*H;
6
10
WRITELN;
5
WRITE ( = , S:7:2);
readln
= 40.00
END.

3. , , :

R R1 R2

R1 R2
R1 R2

R1; R2, R
RPOS; R RPAR.

R2
R1
.
PROGRAM PR;

VAR
R1, R2 : REAL; { }
RPOS, RPAR: REAL; { } R1
BEGIN
20
WRITELN ( R1); READ (R1);
R2
WRITELN ( R2); READ (R2);
30
RPOS:=R1+R2;
RPAR:=R1*R2/(R1+R2);
, R= 50.00
WRITELN;
, R= 12.00
WRITELN ( , R= , RPOS:8:2);
WRITELN ( , R= , RPAR:8:2);
readln
END.

4. Y X ,R sin( X / 4)
K N.

, X. PI,
K N OST.

.
PROGRAM PR4;
:

{ }

CONST PI=3.14;
VAR
Y, R, X : REAL;
K, N, OST : INTEGER;
BEGIN
WRITELN (
! );
WRITELN ( X, K, N :);
READ (X, K, N);
Y := SQRT (X);
R := SIN( X+PI/4);
OST := K MOD N;
WRITELN ( :);
WRITELN (Y= , Y:6:2 );
WRITELN (R= , R:6:2);
WRITELN ( = , OST : 3);
WRITE (
!);
readln
END.

!
X, K, N :
6.25
17
3
:
Y= 2.50
R= 0.68
OST= 2
!


: F R , F N , R D 2
: ) N=47, D=2,5
) N=1225, D=16
) N=6.25, (R )

:
1. .
2. .
3. (RUN).
,
.
4.
)
: F = 7.0 , R =6.25
5. )
. F=35.0, R=256.00
6. ( , R)
. F= 2.5
7. Alt +X


,
,
.
y = x+1, x < 0, y=2x,
:
x 0.
: x
.
: y=x+1, y= 2x.

, .

IF THEN 1
ELSE 2
IF (), THEN (), ELSE () -- , 1,
2 -- .
, 1, ( )
-- 2. 1 2 .
,
. :
IF X< 0 THEN Y:=X+1 ELSE Y:= 2*X
X IF.


, ,
.
.
B
: B:=X<0
IF B THEN Y:=X+1
ELSE Y:=2*X
. A=N+40, 15, 25.
B=M+1.
IF ( N > 15) AND ( N <25) THEN A:= N+40
ELSE B:= M+1
:
N<15 N<25
A=N+40. N M .


.
,
, ELSE IF,
, :

IF A = B

THEN
IF C < D THEN X:=1
ELSE X:=2

ELSE X:=3
:

1, A=B C<D

X=

2, A=B C>=D

3, A<>B.


:
IF
THEN _1
ELSE _2
, , ,
, - .

. THEN ELSE :
IF
BEGIN
_1;
_2;
...
_n-1;
_n
END
ELSE
BEGIN
_1;
_2;
...
_n-1;
_n
END

THEN

ELSE .


.
.
, A>B, :
Y1=7, Y2=A, Y3=A+B.
A<=B, T1=2A T2=A-B.

IF A>B THEN
BEGIN
Y1:=7;
Y2:=A;
Y3:=A+B
END
ELSE
BEGIN
T1:=2*A;
T2:=A-B
END

.
, .
: THEN
ELSE , BEGIN - END
.
.


:
IF THEN _1
, 1; (
) IF. ,
IF A>15 THEN Y:=X-7;
Z:=SUM+1;
. , - . A>15 , Y. A>15
, .. A<=15, Z:=SUM+1.
,
.
, ELSE ( ,
). , :
IF A>15 THEN Y:=X-7
ELSE;
Z:=SUM+1;
THEN.
:
IF A<=15 THEN
ELSE Y:=X-7;
Z:=SUM+1;
>
<= . , THEN
ELSE ( Y:=X-7 ).


5.

, X Y
R . .
, ,

x 2 y 2 R , ..
a

xa2 ya2 R

xa2 ya2 R 2

PROGRAM PR5;
VAR XA, YA, R, L:REAL;
BEGIN
WRITE ( XA, YA, R);
READ ( XA, YA, R);
L:=SQR(XA)+SQR(YA);
IF L < SQR( R )
THEN WRITELN
( )
.
ELSE WRITELN ( )
END.

L
R. R, THEN, ..
c .

.
() ,
-
.
:
CASE OF
1: 1;
2: 2;
...
N: N
END
CASE ( ), OF (), END () - .
.
,
.
.
,
.
,
(REAL).
. .



CASE

K+1
5:
11 :
4:
7:

OF
Y:=SQR(X);
Y:=SQRT(X);
Z:=4*(A-B);
WRITE(A,B)

END

K+1 5,
Y:=SQR(X) ,

END. , K+1
11, 4 7,
.
K .
, K, X, A, B
CASE.



, :
CASE S OF
+, -, *, / : P:=1;
A, B : P:=2;
. : P:=3
END

S

. S
+, -, *, / , P 1.
S A B,
2. S . ,
3.


6.

.
5.
PROGRAM PR6;
VAR N: INTEGER; { }
BEGIN
WRITELN ( :);
READ ( N );
CASE N
OF
1 : WRITELN( - MONDAY );
2 : WRITELN( - TUESDAY );
3 : WRITELN( - WEDNESDAY );
4 : WRITELN( - THUESDAY );
5 : WRITELN( - FRIDAY );
6 : WRITELN( - SATURDAY );
7 : WRITELN( - SUNDAY );
END;
END.

:
:
5
-FRIDAY


:
,
.
.
, .
, :
GOTO

1-9999.

:
GOTO 32;
10: A:=2;
. . .
32: Y:=X/Z;
GOTO 32 32.


, , ,
.
GOTO 32 ,
.
,
.

:

LABEL.

LABEL ;
:
LABEL _1, _2, , _n;

:
LABEL 10, 32;



.
.
.
.
. ,
,
IF A > B THEN GOTO 1 ;
A := A - B ;
GOTO 2 ;
1 : A := A+ B ;
2 : Y := A ;
:
IF A > B THEN A := A + B
ELSE A := A - B ;
Y := A ;

. ,
, ,
LN
SQRT
, ,
:
IF

Y<=0

IF

Y<0

THEN GOTO 100


ELSE A := X * LN (Y);
THEN GOTO 100
ELSE B := X + SQRT(Y);

S:= T - COS (PT);


IF
S = 0 THEN
GOTO 100
ELSE R := 257 * W / S ;
100 : WRITE ( );

, ,
100.
.



7 : . = , Y=3. A<B,
Y=2. A>B Y=3. .
.
Program Pr6;
Var
a,b : integer; { }
y : integer; { }
begin
writeln( );
readln(a,b);
if a = b then y:=1
else if a < b then y:=2
else y:=3 ;
writeln( : );
write(y=,y)
end.

9
34
:
y=2



8: , X ,Y
X1,X2,Y1,Y2.
.X
,
X
XX

Y Y1
Y Y2

:
Program Pr7;
var x1,x2,y1,y2:real;{ - }
:
x,y :real;
{ }
x1=3; x2=19; y1=5; y2=9
begin
writeln( 1,2, y1,y2 );
:
readln(x1,x2,y1,y2);

writeln( x,y );
readln(x,y);
if ( x>=x1) and (x<=x2) and (y>=y1) and (y<=y2)
then writeln( );
else
writeln( );
end.




,
.
:

1. ();
2. ();
3. .
,
.

.
.
.
.
: , .

,
. .



( ) ,
, , .
:
WHILE DO
BEGIN

END;
WHILE ( ) DO () --- .
.
. ,
. ,
. ,
.
, ,
.
.



, BEGIN ---END ,
WHILE DO
: A:=1 ;
N:=1 ;
WHILE 2*A < = 3* N +1 DO
BEGIN
A:=A+2 ;
N:=N+1 ;
END;
2a<=3n+1 ,
. N,
:
A
N
2A<=3N+1

1
1
2<=4

3
2
6<=7

5
3
10<=10

7
4
14<=13

A=7 N=4
(.. END).



, , , . :
REPEAT
;
UNTIL ;

REPEAT () UNTIL ( ) -- .
.
(
) , .

. , ,
.
,
, ,
.
,
UNTIL,

BEGIN --- END.
.



,
,
.
: Y=X*X X=8, 6, 4, 2.
:
X:=8;
REPEAT
Y:=X*X;
WRITELN(X:3,Y:5);
X:=X-2;
UNTIL X<0
X=8.
: Y
X; X Y;
X 2 X.
, X<2
.
:
X
8
6
4
2
0
Y
64
36
16
4
_
X<2

False

False

False

False

TRUE


,
, .
:
FOR i:=m1 TO m2 DO
BEGIN

END
FOR (), TO(), DO () - ; i -
; m1, m2 - .

i m1 m2
.
, m1
m2 , (REAL);
i ,
+1 -1. ,
+1. ,
-1 FOR TO
DOWNTO.


:
: .

FOR I:=1 TO 5 DO
BEGIN
A:=2*I;
B:=2*I+1;
WRITELN(A:3, B:3)
END
,
i 1 5.
:
I .. 1
A .. 2
B .. 3

2
4
5

3
6
7

4
8
9

5
10
11


5 1
:
FOR I:=1 DOWNTO 1

DO

BEGIN
A:=2*I;
B:=2*I+1;
WRITELN(A:3, B:3)

END;

:
I

10

..

11


,
BEGIN - END .
:
FOR I:=m1 TO m2 DO ;

FOR I:=m1 TO m2 DO
;

+1 m1 > m2,
.

. ,
i =m2, i .


: .
,
, :
PROGRAM Pr9;
Var sim:char;
BEGIN
writeln( );
For sim:=A TO Z

DO

WRITE( ,sim)
END.
:

ABC D EFGHI JK LMN OPQR STUVWXYZ


.
,

. .
: Y=2K+N
N=1, 2, 3 K=2, 4, 6, 8.
, N K
12 Y.
: N -
, K - . N
K 2, 4, 6, 8. ,
N, K, Y .
:


PROGRAM PR;
VAR N,K,Y: INTEGER;
BEGIN
FOR N:=1 TO 3 DO
BEGIN
K:=2;
WHILE K<=8 DO
BEGIN
Y:=2*K+N;
WRITELN (N:4, Y:4);
K:=K+2
END
END
END.


FOR,

-
WHILE.


:
N 1
1
1
1
2
2
2
2
3
3
3
3
K 2
4
6
8
2
4
6
8
2
4
6
8
Y 5
9
13
17
6
10
14
18
7
11
15
19



: . .
{ }
Pujgram CA;
var i:integer; { }
n: integer; { }
s :real;
{ }
t: real; { }
begin
t:=0;
writeln( );
read(n);
for i:=1 to n do
begin
write( );
read(s);
t:=t+s;
end;
t:=t/n;
writeln(------------------------------------------);
writeln( =, t:5:2);
end.

:

6

8

7

9

7

9
------------------------------------------- = 7.50



: , . ,
- R, DR;
- RK. V, - VM.
Program e10 ;
const pi=3.14;
:
var
r,rk: real;
(* *);
r :
v,vm: real;
(* *);
0.2
dr:real;
(* *);
begin
rk :
writeln( r : );
1.8
read(R);
dr :
writeln( rk : );
read(rk);
0.4
writeln( dr : )
r= 0.20 v= 0.033
read(dr);
vm:=0;
r= 0.60 v= 0.904
while r<= rk do
r= 1.00 v= 4.187
begin
v:=4*pi*r*r*r/3;
r= 1.40 v= 11.488
vm:=vm+v;
r= 1.80 v 24.417
writeln( r= , r:6:2, :5, v= , v:7:3);
*****************************
r:=r+dr;
end;
VM= 41.029
Writeln ( **************************** );
Writeln( VM=, VM:8:3)
end.



: .
Enter.

. : ,
, WHILE.
.
(NOT EOLN), .
program e3 ;
var buck:char;
k,n :integer;
begin
k:=0; n:=0;
writeln( );
while not eoln do
begin
read(buk);
n:=n+1;
if buk=T then k:=k+1;
end;
writeln;
writeln( = , n:3);
writeln( =, k:3)
end.

:

PTSPTWETPOGZPRTLO
= 17
= 4



: ,
.
:
Program pr;

const
0
32.0
1
33.8
const1=1.8;
( * * )
2
35.6
const2=32.0;
( *
*)
3
37.4
4
39.2
var
5
41.0
centemp:integer; ( * *)
6
42.8
fartemp:real;
( * *)
7
44.6
8
46.4
begin
9
48.2
writeln(
);
10
50.0
11
51.8
for centemp:=0 to 20 do
12
53.6
begin
13
55.4
fartemp:=centemp*const1+const2;
14
57.2
15
59.0
writeln(centemp:3, :8, *, , fartemp:6:1);
16
60.8
end;
17
62.6
18
64.4
end.
19
20

66.2
68.0



:
. ODD.
2, - ; - .
WHILE , EOLN:
,
Enter.
Program e4;

var
:
kn,kc,x: integer;

5
begin
7
kc:=0; kn:=0;
33
writeln( );
16
while not eoln do
13
begin
4
read(x);
10
if odd(x) then kn:=kn+1
71
else kc:=kc+1;
end;
writeln( : );
writeln( , kc:4);
writeln( , kn:4);
end.

9
:
3
6

EXIT