const
A: array [-1..2] of Integer = (0,1,2,3);
В: array [5..7] of Integer = (4,5,6);
begin
ArrayPrint(A);
ArrayPrint(B);
end;
begin
ArrayPrint ( [0,1,2,3]);
ArrayPrint([4,5,6]);
end;
var
i,j,k,l,m: Integer;
Sum: Double;
NItem: Integer;
begin
Result := -1E-309;
if ((VarType(V) and VarArray) <> VarArray) or
(VarArrayDimCount(V) > 5) then Exit;
Sum := 0;
NItem := 0;
// Подсчитываем количество элементов массива
for k := 1 to VarArrayDimCount(V) do
NItem := NItem+VarArrayH'ighBound(V, k)-VarArrayLowBound(V,k) ;
// Подсчитываем сумму элементов
case VarArrayDimCount(V) of
1: for i "VarArrayLowBound(V,1) to VarArrayHighBound(V,1) do
Sum := Sum+V[i] ;
2: for i =VarArrayLowBound(V,1) to VarArrayHighBound(V,1) do
for j :=VarArrayLowBound(V,2) to VarArrayHighBound(V,2) do
Sum := Sum+V[i,j] ;
3: for i: =VarArrayLowBound(V,1) to VarArrayHighBound(V,1) do
for j: =VarArrayLowBound(V,2) to VarArrayHighBound(V,2) do
for k: =VarArrayLowBound(V,3) to VarArrayHighBound(V,3) do
Sum := Sum+V[i,j,k] ;
4: for i: =VarArrayLowBound(V,1) to VarArrayHighBound(V,1) do
for j: =VarArrayLowBound(V,2) to VarArrayHighBound(V,2) do
for k :=VarArrayLowBound(V,3) to VarArrayHighBound(V,3) do
for l: =VarArrayLowBound(V,4) to VarArrayHighBound(V,4) do
Sum := Sum+V[i,j,k,1];
5: for i:=VarArrayLowBound(V,1) to VarArrayHighBound(V,1) do
for j :=VarArrayLowBound(V,2) to VarArrayHighBound(V,2) do
for k: =VarArrayLowBound(V,3) to VarArrayHighBound(V,3) do
for 1 :=VarArrayLowBound(V,4) to VarArrayHighBound(V,4) do
for m:= VarArrayLowBound(V,5) to VarArrayHighBound(V,5) do
Sum := Sum+V[i,j,k,1,m];
end;
Result := Sum/NItem
end;