uses crt;
const nmax=20;
var a:array[1..nmax,1..nmax]of integer;
n,i,j,sum,k,max,l:integer;
p:longint;
begin
clrscr;
randomize;
repeat
write('Vvedite razmernost matricy do ',nmax,' n= ');
readln(n);
until n in [1..nmax];
Writeln('Matrica:');
for i:=1 to n do
begin
for j:=1 to n do
begin
repeat
a[i,j]:=random(10)-2;
until a[i,j]<>0;
write(a[i,j]:4);
end;
writeln;
end;
for i:=1 to n do
begin
k:=0;
for j:=1 to n do
if a[i,j]<0 then k:=1;
if k=0 then
begin
p:=1;
for l:=1 to n do
p:=p*a[i,l];
writeln('Proizvedenie v stroke ',i,'=',p);
end;
end;
write('Press Enter...');
readln;
max:=a[n,1];
for l:=1 to 2*n-1 do{количество диагоналей}
begin
sum:=0;
if l<n then{если брать и главную, то if l<=n}
begin
for i:=n-l+1 to n do
for j:=1 to l do
if j=i-n+l then sum:=sum+a[i,j];
writeln('Сумма ',l,'=',sum);
if sum>max then max:=sum;
end
else if l>n then
begin
for i:=1 to 2*n-l do
for j:=l-n+1 to n do
if j=i+l-n then sum:=sum+a[i,j];
writeln('Сумма ',l,'=',sum);
if sum>max then max:=sum;
end;
end;
write('Maximalnaya summa=',max);
readln
end.