() ,
. :
n! = n*(n-1)!
,
" "
, .
:
if n < 2
then fact:=l else fact:=n*fact(n-1);
,
:
-> ->
-> -> ...
,
,
,
forward:
{
}
procedure (< >);
forward; {
}
procedure (<
>);
begin
(...); {
}
end; {
}
procedure A;
{ } begin
(...); {
} end;
,
.
. ,
. , , n!,
:
= =1;
for i:=l to
n do p:=p*i;
fact:=p;
,
, ,
(., , quicksort
" ").
5.01.
XIII .,
.
- , ,
.
. , k
. :
, :
fk
= fk-2 + fk-1
,
:
1,1,2,3,5,8,13,21,34,55,...
0,1,1,2,3,5,8,13,21,34,.....
,
0. : fit>(22)=17711,
fib(23) =28657 24- .
,
fib :
f ib (k) = (
( (1+sqrt (5) ) /2)*k- ( (1-sqrt (5) ) /2} ^k) /sqrt (5)
.
, . .
k
.
5_01.bas
DECLARE FUNCTION
FIB%(N%)
INPUT "
- ",N%
PRINT "
";N%;" ";FIB%(N%)
END
FUNCTION FIB%(N%)
IF N% < 2
THEN
FIB%=N% ELSE
FIB%=FIB%(N%-2)+FIB%(N%-1)
END IF
END FUNCTION
5_01.
#include <stdio.h>
#include <conio.h>
1 ()
()
. :
H(kl,k2)
= HO(k2,kl) // , kl < k2
H(0,k)
= k // , ..
H(kl,k2)
= H(k3,kl) // k3 - k2 kl.
, : k1*m + k3 = k2 // m - k2 k1
kl
k2 , k3 .
:
2 ()
. :
(120,84)=(84,120)=(36,84)=(12,36)=(0,12)==12
.
5_02.bas
DECLARE FUNCTION
NOD&(NlS,N2&)
PRINT "
2 , "
INPUT "",M&,N&
PRINT "
";NOD&(M&,N&)
END
FUNCTION NOD&(N1&,N2&)
IF Nl&=0 THEN
NODS=N2&
ELSE
NOD&=NOD&(N2& MOD N1&,N1&)
END IF
END FUNCTION
5_02.
#include <stdio.h>
#include <conio.h>
long nod(long
nl,long n2);
main() {
long m,n;
printf("\n
2 , \n");
scanf("%ld
%ld",&n,&m);
printf("
%ld",nod(m,n));
getch(); }
long nod(long
n1,long n2) {
if(nl==0) return
n2;
return nod(n2%nl,nl);
}
5_02.pas
program Euclid;
var
n,m:longint;
function nod(nl,n2:longint):longint;
begin
if nl=0 then
nod:=n2
else nod:=nod(n2 mod n1,n1);
end;
begin
writeln('
');
readln(n,m);
writeln{'x
',nod(n,m));
readln; end.
5.03.
"
" . XIX .
,
, . k ,
"" ( ,
, , , ).
.
, ,
.
,
, , 2k-i.
k=1 k=2 . :
k-1,
k. ,
k-1 2k-1-1 . k
:
,
, k , :
2k-1
- 1 + 1 + 2k-1 -1 = 2k-l
1 ()
,
. :
MoveAll(k,from,to,tmp)
MoveOne(from,to)
k from
to, tmp.
from to.
2 (QBasic)
% .
MoveOne
STATIC.
3 ()
to, . .
for.
5_03.bas
DECLARE SUB
MoveAll(k%,from$,to$,tmp$)
DECLARE SUB
MoveOne(from$,to$)
CLS
INPUT "
",k%
MoveAll k%,"A","C","B"
END
SUB MoveAll
(k%, from$, to$,tmp$)
IF k%=0 THEN
EXIT SUB
MoveAll k%-l,from$,tmp$,to$
MoveOne from$,to$
MoveAll k%-l,trap$,to$,from$
END SUB
SUB MoveOne(from$,to$)
STATIC
m%=m%+l
PRINT USING
"#### : &--> & ";m%;from$;to$ END SUB
5_03.
#include <stdio.h>
#include <conio.h>
void MoveAll(int
k,char from,char to,char trap);
void MoveOne(char
from,char to);
int m=0;
main () {
int k;
clrscr () ;
printf("\n
- ");
scanf("Id",&k);
MoveAll(k,'A','C','B');
getch(); }
void MoveAll(int
k,char from,char to,char tmp)
{
if(k==0) return; MoveAll(k-1,from,tmp,to);
MoveOne(from,to);
MoveAll(k-1,tmp,to,from); }
void MoveOne(char
from,char to) {
m++;
printf("\n%4d
: %c --> %c",m,from,to); }
5_03.pas
program Hanoi;
uses Crt; var
k:integer; const
m: integer=0;
procedure MoveOne(from,tol:char);
begin
inc (m) ;
writeln(m:4,from:2, ' > ',tol);
end;
procedure MoveAll(k:integer;from,tol,tmp:char);
begin
if k = 0 then
exit;
MoveAll(k-1,from,tmp,tol);
MoveOne(from,tol);
MoveAll(k-1,tmp,tol,from);
end;
begin
clrscr;
write(' - ') ;
readln(k);
MoveAll(k, '', '', '');
readln;
end.
10.11.2021 - 12:37: - Personalias -> WHO IS WHO - - _. 10.11.2021 - 12:36: - Conscience -> . ? - _. 10.11.2021 - 12:36: , , - Upbringing, Inlightening, Education -> ... - _. 10.11.2021 - 12:35: - Ecology -> - _. 10.11.2021 - 12:34: , - War, Politics and Science -> - _. 10.11.2021 - 12:34: , - War, Politics and Science -> . - _. 10.11.2021 - 12:34: , , - Upbringing, Inlightening, Education -> , - _. 10.11.2021 - 09:18: - New Technologies -> , 5G- - _. 10.11.2021 - 09:18: - Ecology -> - _. 10.11.2021 - 09:16: - Ecology -> - _. 10.11.2021 - 09:15: , , - Upbringing, Inlightening, Education -> - _. 10.11.2021 - 09:13: , , - Upbringing, Inlightening, Education -> - _. |