const N=5;
var i,j,max,sum,i1,j1:integer;
a:array [1..N,1..N] of integer;
st:boolean;
begin
sum:=0; max:=0; i1:=0; j1:=0;
st:=false;
randomize;
for i:=1 to n do
for j:=1 to n do
a[i,j]:=random(31)-10;
write(a[i,j]:4);
if st = false then
max:=a[i,j];
st:=true;
end
else
if a[i,j]>max then
if a[i,j]>0 then
i1:=i;
j1:=j;
end;
writeln;
for i:=1 to i1-1 do
sum:=sum+a[i,j];
for j:=1 to j1-1 do
sum:=sum+a[i+1,j];
writeln('MAX: ',max);
writeln('SUM: ',sum)
end.
Объяснение:
const N=5;
var i,j,max,sum,i1,j1:integer;
a:array [1..N,1..N] of integer;
st:boolean;
begin
sum:=0; max:=0; i1:=0; j1:=0;
st:=false;
randomize;
for i:=1 to n do
begin
for j:=1 to n do
begin
a[i,j]:=random(31)-10;
write(a[i,j]:4);
if st = false then
begin
max:=a[i,j];
st:=true;
end
else
if a[i,j]>max then
max:=a[i,j];
if a[i,j]>0 then
begin
i1:=i;
j1:=j;
end;
end;
writeln;
end;
writeln;
for i:=1 to i1-1 do
for j:=1 to n do
sum:=sum+a[i,j];
for j:=1 to j1-1 do
sum:=sum+a[i+1,j];
writeln('MAX: ',max);
writeln('SUM: ',sum)
end.
Объяснение: