Const m = 3; n = 4; var a: array[1..m, 1..n] of integer; i, j, k, t: integer;
begin Randomize; Writeln('Исходный массив'); for i := 1 to m do begin for j := 1 to n do begin a[i, j] := Random(101) - 50; Write(a[i, j]:4) end; Writeln end; { Пузырьковая сортировка по возрастанию в столбцах } for j:=1 to n do for k := 1 to m-1 do for i := 1 to m-1 do if a[i,j] > a[i+1,j] then begin t := a[i,j]; a[i,j] := a[i+1,j]; a[i+1,j] := t end; Writeln('Сортировка по столбцам'); for i := 1 to m do begin for j := 1 to n do Write(a[i, j]:4); Writeln end end.
Program t1; var i, j: integer; mas: array [1..10] of integer; begin randomize; writeln ('сгенерированный масив: '); for i := 1 to 3 do writeln; for j := 1 to 4 do begin mas[i,j] := random (100) - 50; write (mas[i,j]); end; end;
begin for i:=1 to 3 do for i:=1 to 3 do for k:=1 to 3-i do if M[k] > M[k+1] then swap(mas[k],mas[k+1]) end end; end; writeln ('отсортированный по возрастанию массив (построчно): '); for i := 1 to 3 do writeln; for j := 1 to 4 do write (mas[i,j]); end; end; end.
m = 3;
n = 4;
var
a: array[1..m, 1..n] of integer;
i, j, k, t: integer;
begin
Randomize;
Writeln('Исходный массив');
for i := 1 to m do
begin
for j := 1 to n do
begin
a[i, j] := Random(101) - 50;
Write(a[i, j]:4)
end;
Writeln
end;
{ Пузырьковая сортировка по возрастанию в столбцах }
for j:=1 to n do
for k := 1 to m-1 do
for i := 1 to m-1 do
if a[i,j] > a[i+1,j] then
begin t := a[i,j]; a[i,j] := a[i+1,j]; a[i+1,j] := t end;
Writeln('Сортировка по столбцам');
for i := 1 to m do
begin
for j := 1 to n do Write(a[i, j]:4);
Writeln
end
end.
Тестовое решение:
Исходный массив
49 -10 27 -22
46 42 -17 -12
34 -50 7 24
Сортировка по столбцам
34 -50 -17 -22
46 -10 7 -12
49 42 27 24
var
i, j: integer;
mas: array [1..10] of integer;
begin
randomize;
writeln ('сгенерированный масив: ');
for i := 1 to 3 do
writeln;
for j := 1 to 4 do
begin
mas[i,j] := random (100) - 50;
write (mas[i,j]);
end;
end;
begin
for i:=1 to 3 do
for i:=1 to 3 do
for k:=1 to 3-i do
if M[k] > M[k+1] then swap(mas[k],mas[k+1])
end
end;
end;
writeln ('отсортированный по возрастанию массив (построчно): ');
for i := 1 to 3 do
writeln;
for j := 1 to 4 do write (mas[i,j]);
end;
end;
end.