//PascalABC.NET 3.2 сборка 1318
Const
n=3;
m=4;
Var
ma:array[1..n,1..m] of integer;
ZeroCount:array[1..m] of integer;
i,j,k,buf:integer;
begin
for i:=1 to n do
for j:=1 to m do
readln(ma[i][j]);
writeln('Matrix:');
for i:=1 to n do
begin
for j:=1 to m do
write(ma[i][j]:4);
writeln;
end;
writeln('Count of zero elements:');
for j:=1 to m do
begin
for i:=1 to n do
if ma[i][j]=0 then inc(ZeroCount[j]);
writeln(j,':',ZeroCount[j]);
end;
for i:=1 to m-1 do
for j:=i+1 to m do
if ZeroCount[i] begin
for k:=1 to n do
begin
buf:=ma[k][i];
ma[k][i]:=ma[k][j];
ma[k][j]:=buf;
end;
buf:=ZeroCount[i];
ZeroCount[i]:=ZeroCount[j];
ZeroCount[j]:=buf;
end;
writeln('Final matrix:');
for i:=1 to n do
begin
for j:=1 to m do
write(ma[i][j]:4);
writeln;
end;
end.
Пример работы программы:
Matrix:
2 0 0 -1
0 0 1 -1
-2 -2 1 -2
Count of zero elements:
1:1
2:2
3:1
4:0
Final matrix:
0 2 0 -1
0 0 1 -1
-2 -2 1 -2