Определить номер столбца в матрице, сумма положительных элементов которой является наибольшей. Если таких столбцов несколько, то вывести номера всех этих столбцов — Pascal(Паскаль)

uses crt;
const nmax=20;
var a:array[1..nmax,1..nmax] of integer;
    n,m,i,j:byte;
    s,max:integer;
begin
clrscr;
randomize;
repeat
write('Количество строк=');
readln(m);
until m in [1..nmax];
repeat
write('Количество столбцов=');
readln(n);
until n in [1..nmax];
writeln('Исходная матрица:');
for i:=1 to m do
 begin
   for j:=1 to n do
    begin
     a[i,j]:=random(10)-2;
     write(a[i,j]:3);
    end;
   writeln;
 end;
writeln;
max:=0;
for j:=1 to n do
 begin
  s:=0;
  for i:=1 to m do
  if a[i,j]>0 then s:=s+a[i,j];
  a[m+1,j]:=s;
  if s>max then max:=s;
 end;
for i:=1 to n do
if a[m+1,i]=max then writeln('Столбец № ',i);
readln
end.
1

Leave a Comment

80 − 74 =