Professional Documents
Culture Documents
minArrays: *
minArrays (s)
if len s = 1
then hd s
else
if hd s minArrays (tl s)
then hd s
else minArrays (tl s)
Hm tnh tch cc phn t ca mng
tich : *
tich (s)
if len s = 1
then hd s
then (hd s) * tich(tl s)
Hm tm phn t ln nht khng dng trong mng
PhanTuLonNhatKhongDuongTrongmang(a:R*) r:R
Pre a # [ ]
Post ((r
elems a ) ( n elems a ) ( r 0 (n 0)
n r )
elems a ) ( n elems a ) ( r 0 (n 0)
r n )
a div i = i) v (r = false) ( i N 1
= i)
Hm kim tra s nguyn t
isPrime: N B
isPrime (i) i1 dN1 d divides i d=1 d=i
Hm kim tra l nm nhun
isNamNhuan : N1 B
isNamNhuan(n) n mod 4 =0 n mod 100 = 0
Cu 31:
TapHopGiaTriTrongMang(a:N*)rs:N*
Pre a # [ ]
Post
Cu 32:
a div i
ViTriPhanTuLonNhatKhongDuongTrongMang(a:N*) rs:N
Pre a # [ ]
Post
Cu 34:
SoChinhPhuongLonNhat ( x : N ) r : N
Pre
Post
Cu 35:
SoNgToMin(a:N1)rs:N1
Pre
Post (isPrime(rs)
rs a ) (( k a ) isPrime(k) k r )
Cu 36 :
DemSoNamNhuan : NxN
DemSoNamNhuan(a,b)
N
card{x:N|0<a x b isNamNhuan(x)}
Cu 37 :
DemSoNgTo: NxN
DemSoNgTo (a,b)
Cu 38 :
card{x:N|0<a x b isPrime(x)}
Uscln(a:N*) r:N
Pre
x elems a x 0
minArrays( a) ) ^(
Hoac (pd(n
minArrays( a) ) ^(
) ^ r = true)
)) ^ r = false)
Cu 39 :
Bcnn : N
Bcnn (n)
tich ( n ) /Ucln(n)
Cu 40:
SapXepMangTang : R*
SapXepMangTang(s)
B
i, j inds s i > j s(i) s(j)