Const m=4; n=15; var i,j,j0: integer; a:array[1..m,1..n] of integer; jExit,iExit:Boolean; begin Randomize; for i:=1 to m do begin writeln; for j:=1 to n do begin a[i,j]:=random(2); write(a[i,j]:2) end end; writeln; j:=0; jExit:=false; repeat j:=j+1; i:=1; iExit:=false; if a[i,j]=0 then begin repeat i:=i+1; if a[i,j]<>0 then iExit:=true until iExit or (i=m); if i=m then jExit:=true end until jExit or (j=n); if a[i,j]=0 then writeln('Нулевой столбец ',j) else writeln('Нет нулевых столбцов'); end.
// PascalABC.NET 3.0, сборка 1156 от 30.01.2016 function Avg(a:array[,] of integer):real; begin var s:=0; var k:=0; foreach var e:integer in a do if e>0 then begin s+=e; Inc(k) end; if k>0 then Result:=s/k else Result:=1e-100; end;
begin var A:=MatrixRandom(4,4,-50,50); Writeln(A); Writeln('Среднее арифметическое положительных равно ',Avg(A):0:3); var B:=MatrixRandom(5,5,-30,30); Writeln(B); Writeln('Среднее арифметическое положительных равно ',Avg(B):0:3); var C:=MatrixRandom(4,5,-25,38); Writeln(C); Writeln('Среднее арифметическое положительных равно ',Avg(C):0:3); end.
Тестовое решение: [[35,35,5,-47],[14,34,35,-13],[25,-5,35,-29],[-7,10,-12,12]] Среднее арифметическое положительных равно 24.000 [[-12,-17,-10,19,14],[20,17,-27,-2,16],[-3,-21,30,2,10],[5,-3,-17,-3,18],[0,-26,29,1,-22]] Среднее арифметическое положительных равно 15.083 [[-5,-11,17,-4,15],[15,17,-24,36,15],[-8,-3,-22,28,-25],[-21,6,12,31,-1]] Среднее арифметическое положительных равно 19.200
var
i,j,j0: integer;
a:array[1..m,1..n] of integer;
jExit,iExit:Boolean;
begin
Randomize;
for i:=1 to m do begin
writeln;
for j:=1 to n do begin
a[i,j]:=random(2);
write(a[i,j]:2)
end
end;
writeln;
j:=0; jExit:=false;
repeat
j:=j+1; i:=1; iExit:=false;
if a[i,j]=0 then begin
repeat
i:=i+1;
if a[i,j]<>0 then iExit:=true
until iExit or (i=m);
if i=m then jExit:=true
end
until jExit or (j=n);
if a[i,j]=0 then writeln('Нулевой столбец ',j)
else writeln('Нет нулевых столбцов');
end.
Тестовый пример:
0 1 1 1 1 0 1 0 1 0 0 0 0 0 1
0 0 1 0 1 0 0 0 1 1 0 0 0 0 0
1 1 0 0 0 1 0 1 1 1 1 1 0 1 1
1 1 1 0 1 0 1 0 0 1 0 1 0 1 0
Нулевой столбец 13