P S P. , . , .
( ):
1) ( ).
procedure P(n);
begin
S; //
if then (n-1)
end;
2) ( ).
procedure P(n);
begin
if then P(n-1);
S; //
end;
3) ( ).
procedure P(n); begin S1; // ; if then P(n-1); S2; // end; | procedure P(n); begin if then begin S1; // P(n-1); S2 // end end. |
4) , , , .
procedure P(n);
begin
S; //
if 1 then P(n-1);
S1; //
if 2 then P(n-1);
S2 //
end;
procedure Print(x: integer);
begin
if x > 9 then Print(x div 10); // x
write(x mod 10:3) //
end;
. 10 , . 10 .
x=1234, Print:
Print(1234); Print(123); Print(12); Print(1);
, Print 1.
Print(12) 2, Print(123) 3, Print(1234)‑ 4.
: 1 2 3 4
, , , 1. 1, .
, , .. . . A[L] , A[L] .
|
|
const N=10;
type vector=array[1..N] of integer;
var V:vector; max:integer;
function RMax(const A:vector; L:integer):integer;
{ L , .}
var M: integer;
begin
if L=1 then RMax:=A[1] // A[1] ;
else begin
M:= RMax(A, L-1); // 1
if A[L]>M then RMax:=A[L] //
end
end;
begin... max:=RMax(V, N);...
end.
19.8.3.
, (C. Hoare) 1960 ., .