
В заданной матрице размерности M на N, сформированной случайным образом, вставить первую строку перед всеми строками, в которых есть 0, а первый столбец после всех столбцов, в которых 0 отсутствует..
Код: Выделить всё
program l5(4);
uses Crt;
const m=5;
n=4;
var a,b:array[1..m,1..n] of integer;
j,i:integer;
flag:boolean;
begin
write ('Vvedite razm mas stroki m='); readln(m);
write ('Vvedite razm mas stolb n='); readln(n);
Setlength(a,m,n);
Setlength (b,m,n);
randomize;
for i:=0 to (m-1) do
begin
for j:=0 to (n-1) do
begin a[i,j]:=random(21)-10;
write(a[i,j],' ');
end;
writeln;
end;
for i:=0 to (m-1) do
for j:=0 to (n-1) do
read(a[i,j]);
for i:=0 to (m-1) do
begin flag:=false;
j:=0;
while (j<=n-1) and (flag=false) do
begin if a[i,j]=0
then flag:=true;
inc(j);
end;
if flag=true
then
begin inc(m);
Setlength(b,m,n);
for j:=0 to (n-1) do
begin b[i,j]:=a[0,j];
b[i+1,j]:=a[i,j];
end;
end
else
for j:=0 to(n-1) do
b[i,j]:=a[i,j];
end;
for i:=0 to(m-1) do
for j:=0 to (n-1) do
writeln (b[i,j],'');
readln
end.