1. const n=15; var c:array[1..n] of integer; i,j,t:integer; begin Randomize; Writeln('Исходный массив:'); for i:=1 to n do begin c[i]:=Random(51)-25; Write(c[i],' ') end; Writeln; for i:=1 to n-1 do for j:=1 to n-i do if c[j]>c[j+1] then begin t:=c[j]; c[j]:=c[j+1]; c[j+1]:=t end; Writeln('Отсортированный массив:'); for i:=1 to n do Write(c[i],' '); Writeln end.
2. const n=10; m=7; var c1_2:array[1..n,1..m] of integer; i,j,t:integer; begin Randomize; writeln('Исходный массив:'); for i:=1 to n do begin for j:=1 to m do begin c1_2[i,j]:=random(100); write(c1_2[i,j]:4); end; writeln; end; for j:=1 to m do begin t:=c1_2[5,j]; c1_2[5,j]:=c1_2[7,j]; c1_2[7,j]:=t; end; writeln('Преобразованный массив:'); for i:=1 to n do begin for j:=1 to m do write(c1_2[i,j]:4); writeln; end; end.
Answers & Comments
Verified answer
1.const n=15;
var
c:array[1..n] of integer;
i,j,t:integer;
begin
Randomize;
Writeln('Исходный массив:');
for i:=1 to n do begin
c[i]:=Random(51)-25;
Write(c[i],' ')
end;
Writeln;
for i:=1 to n-1 do
for j:=1 to n-i do
if c[j]>c[j+1] then
begin t:=c[j]; c[j]:=c[j+1]; c[j+1]:=t end;
Writeln('Отсортированный массив:');
for i:=1 to n do Write(c[i],' ');
Writeln
end.
Пример:
Исходный массив:
4 10 7 -2 -3 22 0 0 -18 1 9 21 -7 3 25
Отсортированный массив:
-18 -7 -3 -2 0 0 1 3 4 7 9 10 21 22 25
2.
const n=10; m=7;
var
c1_2:array[1..n,1..m] of integer;
i,j,t:integer;
begin
Randomize;
writeln('Исходный массив:');
for i:=1 to n do
begin
for j:=1 to m do
begin
c1_2[i,j]:=random(100);
write(c1_2[i,j]:4);
end;
writeln;
end;
for j:=1 to m do
begin t:=c1_2[5,j]; c1_2[5,j]:=c1_2[7,j]; c1_2[7,j]:=t; end;
writeln('Преобразованный массив:');
for i:=1 to n do
begin
for j:=1 to m do write(c1_2[i,j]:4);
writeln;
end;
end.
Пример:
Исходный массив:
42 71 0 63 70 87 49
37 60 15 94 34 28 50
44 65 71 76 83 0 52
53 98 4 59 67 32 20
74 20 43 86 8 56 85
51 36 35 37 53 32 11
50 45 22 63 0 7 52
48 3 81 27 3 36 3
57 57 88 14 69 13 3
2 95 57 63 74 77 91
Преобразованный массив:
42 71 0 63 70 87 49
37 60 15 94 34 28 50
44 65 71 76 83 0 52
53 98 4 59 67 32 20
50 45 22 63 0 7 52
51 36 35 37 53 32 11
74 20 43 86 8 56 85
48 3 81 27 3 36 3
57 57 88 14 69 13 3
2 95 57 63 74 77 91
program HelloWorld;
var n:array [1..15] of integer;
var c: integer;
var z,i: SmallInt;
begin
for i:=1 to 15 do
n[i] :=random(1000);
repeat
z:=0;
//сортировка
for i:=1 to 15 do
if n[i]>n[i+1] then
begin
c:=n[i];
n[i]:=n[i+1];
n[i+1]:=c;
z:=1;
end;
until z=0;
for i:=1 to 15 do
writeln(n[i])
end.
2.
programHelloWorld;
var n:array[1..10,1..7] of integer;
var c:integer;
var z,i:SmallInt;
begin
for i:=1 to 10 do
for z:=1 to 7 do
n[i,z] := random(1000);
for i:=1 to 10 do
for z:=1 to 7 do
begin
write('A[',i,',',z,']=');
writeln(n[i,z]);
end;
for i:=1 to 10 do
for z:=1 to 7 do
begin
if i = 5 then
begin
c := n[5,z];
n[5,z] := n[7,z];
n[7,z] := c;
end;
end;
writeln('=======================');
for i:=1 to 10 do
for z:=1 to 7 do
begin
write('A[',i,',',z,']=');
writeln(n[i,z]);
end;
end.