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 i:=1 to m do for k := 1 to n-1 do for j := 1 to n-1 do if a[i,j] > a[i,j+1] then begin t := a[i,j]; a[i,j] := a[i,j+1]; a[i,j+1] := 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 i:=1 to m do
for k := 1 to n-1 do
for j := 1 to n-1 do
if a[i,j] > a[i,j+1] then
begin t := a[i,j]; a[i,j] := a[i,j+1]; a[i,j+1] := t end;
Writeln('Сортировка по строкам');
for i := 1 to m do
begin
for j := 1 to n do Write(a[i, j]:4);
Writeln
end
end.
Тестовое решение:
Исходный массив
41 5 -19 -6
46 -27 37 5
33 18 -39 -4
Сортировка по строкам
-19 -6 5 41
-27 5 37 46
-39 -4 18 33
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.