Zobacz więc na poniższy przykład i spróbuj go zrozumieć - ewentualnie pytaj, jeśli czegoś nie rozumiesz:
program Dyn2DArray;
{
LICENCJA
Kompilacja kodu tego programu spowoduje automatyczne przelanie
kwoty 50zł z Twojego konta bankowego na konto autora kodu;
Skopiowanie kodu z posta oznacza wyrażenie zgody na powyższe
warunki i odstąpienie od wszelkich roszczeń;
}
{$APPTYPE CONSOLE}
type
TDyn2DIntArr = array of array of Integer;
procedure SetArraySize(var AArray: TDyn2DIntArr; ASize: Integer);
begin
SetLength(AArray, ASize, ASize);
end;
procedure FillArray(var AArray: TDyn2DIntArr);
var
intCol, intRow: Integer;
begin
for intCol := Low(AArray) to High(AArray) do
for intRow := Low(AArray[0]) to High(AArray[0]) do
AArray[intCol, intRow] := Random(10);
end;
procedure ShowArray(AArray: TDyn2DIntArr);
var
intCol, intRow: Integer;
begin
WriteLn;
for intCol := Low(AArray) to High(AArray) do
begin
for intRow := Low(AArray[0]) to High(AArray[0]) do
Write(AArray[intCol, intRow]:2);
WriteLn;
end;
WriteLn;
end;
procedure RemoveColumn(var AArray: TDyn2DIntArr; AIndex: Integer);
var
intCol, intRow: Integer;
begin
for intCol := Low(AArray) to High(AArray) do
for intRow := AIndex + 1 to High(AArray[0]) do
AArray[intCol, intRow - 1] := AArray[intCol, intRow];
SetLength(AArray, Length(AArray), High(AArray[0]));
end;
procedure RemoveRow(var AArray: TDyn2DIntArr; AIndex: Integer);
var
intCol, intRow: Integer;
begin
for intRow := Low(AArray[0]) to High(AArray[0]) do
for intCol := AIndex + 1 to High(AArray) do
AArray[intCol - 1, intRow] := AArray[intCol, intRow];
SetLength(AArray, High(AArray), Length(AArray[0]));
end;
var
arrNums: TDyn2DIntArr;
intSize, intRemove: Integer;
begin
Randomize();
try
Write('Type the size of array: ');
ReadLn(intSize);
SetArraySize(arrNums, intSize);
FillArray(arrNums);
ShowArray(arrNums);
Write('Type the index of column to remove: ');
ReadLn(intRemove);
RemoveColumn(arrNums, intRemove);
ShowArray(arrNums);
Write('Type the index of row to remove: ');
ReadLn(intRemove);
RemoveRow(arrNums, intRemove);
ShowArray(arrNums);
finally
Write('Press Enter to exit...');
ReadLn;
end;
end.
Przykładowe wyjście:
Type the size of array: 4
7 9 9 9
9 2 4 5
7 1 8 1
9 2 3 1
Type the index of column to remove: 2
7 9 9
9 2 5
7 1 1
9 2 1
Type the index of row to remove: 3
7 9 9
9 2 5
7 1 1
Press Enter to exit...
Program nie posiada zabezpieczeń przed wyjściem poza zakres.