Const n=4; var a:array[1..n,1..n] of integer; i,j,k:integer; begin Randomize; writeln('Исходный массив:'); for i:=1 to n do begin for j:=1 to n do begin a[i,j]:=random(40)-20; write(a[i,j]:4); end; writeln; end; k:=0; for i:=1 to n do if a[i,i]<0 then k:=k+1; writeln('k = ',k); end.
var a:array[1..n,1..n] of integer;
i,j,k:integer;
begin
Randomize;
writeln('Исходный массив:');
for i:=1 to n do
begin
for j:=1 to n do
begin
a[i,j]:=random(40)-20;
write(a[i,j]:4);
end;
writeln;
end;
k:=0;
for i:=1 to n do
if a[i,i]<0 then k:=k+1;
writeln('k = ',k);
end.
Пример:
Исходный массив:
14 14 10 -18
-12 6 -5 1
4 10 11 16
-2 -10 8 -7
k = 1