:
: TURBO PASCAL 7.1
: ,
: 2 .
:
1. ., . Turbo Pascal. .: , 2008. . 157-163, 273-278.
2. .. Turbo Pascal. . 2- . .: , 2007. . 217-220.
3. .. . . . .: , 2008. . 105-107.
:
1. .
2. .
3. .
(), ( ) . , , .
, :
< >::= < > | < >< >
< >::= 0 | 1
, , - ( ); "::=" " ", "|" "".
, , , .
1.
, , . , :
n!=1*2*3*...* n. ,
n <=1.
2.
K(n), n:
. S(n), .
3.
C(m, n), 0 <= m <= n, .
.
. . . , , .
. , , . , , , .
|
|
:
Begin Begin Begin
P; ; ;
; P P;
End; End;
End;
,
P . , , . .
4.
{ }
Function Factorial(N:integer):Extended;
Begin
If N<=1 Then Factorial:=1 Else Factorial:=Factorial(N-1)*N
End;
{ }
Procedure Factorial(N:integer; Var F:Extended);
Begin
If N<=1 Then F:=1 Else Begin Factorial(N-1, F); F:=F*N End
End;
5.
{ }
Function K(N:Longint):Byte;
Begin
If N<10 Then K:=1 Else K:=K(N div 10)+1 End;
{ }
Procedure K(N:Longint; Var Kol:Byte)
Begin
If N<10 Then Kol:=1 Else Begin K(N Div 10, Kol); Kol:=Kol+1 End; End;
6.
{ }
function C(m, n:Byte):Longint;
Begin
If (m=0) or (m=n) Then C:=1 Else C:=C(m, n-1)+C(m-1, n-1)
End;
{ }
Procedure C(m, n: Byte; Var R: Longint);
Var R1, R2: Longint;
Begin
If (m=0) or (m=n) Then R:=1 Else Begin
C(m, n-1, R1);
C(m-1, n-1, R2);
R:=R1+R2
End;
End;
7. .
: , , , .
Program Rec2;
Type LinMas = Array[1..100] Of Integer;
Var A: LinMas;
I, N: Byte;
{ }
Function Summa(N: Byte; A: LinMas): Integer;
Begin
If N = 0 Then Summa:= 0 Else Summa:= A[N] + Summa(N - 1, A)
End;
{ }
Begin
Write(' ? '); ReadLn(N); Randomize;
For I:= 1 To N Do
Begin
A[I]:= -10 + Random(21); Write(A[I]: 4)
End;
WriteLn; WriteLn(': ', Summa(N, A))
End.
. , . .
: .
1, 11 | 6, 16 | ||
2, 12 | 7, 17 | ||
3, 13 | 8, 18 | ||
4, 14 | 9, 19 | ||
5, 15 | 10, 20 |
:
1. .
2. ().
3. .
4. .
5. .
; ; .
|
|