.


:




:

































 

 

 

 


Pascal-




. , , x z, - z=max(x, y), z:=x, z:=y. x y , , . . , .

x>y. x y ( true), z:=x; z:=y ( x=y , , z:=y ).

. :

if B then S1 else S2

if (), then () else () , , S1 S2 .

S1 S2: ( true), S1, S2.

z= max(x, y)

if x>y then z:= x else z:= y

, - , , . : x<0, x:= - x; x>=0, , .. - .

:

if B then S

: true, S; .

then else, else . ( ) , , , .. begin... end ( !). , , x< y , :

if x<y then begin r:=x; x:=y; y:=r end

. ,

if B1 then if B2 then S1 else S2

, , :

if B1 then begin
if B2 then S1 end
else S2

if B1 then begin
if B2 then S1 else S2 end

, .. , else then. .

 

9.

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

1 2 3 4
1 2 3
1 2
 

 

, . 1 2 . 3 , . 4 .

. , .

1. , .

2. 1 1 .

3. 2 2 .

4. - , .

5. 3.

6. 4 .

4 .. , , . 6, , 7, 1.

(-, -) . , .

, .

.

 

10.

: .

( recursio - ) - , .

, , , . , .

, , , ,

, . , ( ).

. , , . , , .

. , 1 :

N! = 1*2*3*... *(N-2)*(N-1)*N
1! = 1
0! = 1

, :

Function NonRecFact(N:integer): LongInt; Var i: integer; { } Res: LongInt; {} Begin Res:= 1; for i:= 1 to N do res:= Res*i; NonResFact:= Res; End;

, , :

N! = (N-1)!*N

, N, N :

Function RecFact(N:integer): LongInt; Begin if N <= 1 then ResFact:= 1 else ResFact:= N*ResFact(N-1); End;

, , :

Program Rekurs; Var N: integer; F: Longint; Function RecFact(N:integer): LongInt; Begin if N <= 1 then ResFact:= 1 else ResFact:= N*ResFact(N-1); End; Begin writeln(' N > '; read(N); F:= RecFact(N); writeln(' ',N,' ',F); End.

" N > ", F:=RecFact(N) RecFact - N. - N<=1. , ResFact 1 . N<=1 , N*ResFact(N-1).

, ResFact(N-1), , , ResFact, ResFact, .., N 1. ResFact ResFact N=1, , ResFact , ResFact , 1 N, ResFact , . ResFact F 1 N, .. N.

, , . N=1 , .. ResFact=1. ResFact.

 

 





:


: 2016-11-12; !; : 564 |


:

:

: , .
==> ...

2033 - | 1666 -


© 2015-2024 lektsii.org - -

: 0.016 .