1. const n=6; var a:array[1..n,1..n] of integer; i,j:integer; begin for i:=1 to n do begin for j:=1 to n do begin a[i,j]:=n*(n-i)+j; write(a[i,j]:4); end; writeln; end; end.
2. const n=5; var a:array[1..n,1..n] of integer; i,j,s,k:integer; begin Randomize; writeln('Исходный массив:'); for i:=1 to n do begin for j:=1 to n do begin a[i,j]:=random(100)-50; write(a[i,j]:4); end; writeln; end; s:=0; k:=0; for i:=1 to n do for j:=1 to i-1 do if a[i,j]>0 then begin s:=s+a[i,j]; k:=k+1; end; writeln('s = ',s,' k = ',k); end.
Answers & Comments
Verified answer
1.const n=6;
var
a:array[1..n,1..n] of integer;
i,j:integer;
begin
for i:=1 to n do
begin
for j:=1 to n do
begin
a[i,j]:=n*(n-i)+j;
write(a[i,j]:4);
end;
writeln;
end;
end.
Результат:
31 32 33 34 35 36
25 26 27 28 29 30
19 20 21 22 23 24
13 14 15 16 17 18
7 8 9 10 11 12
1 2 3 4 5 6
2.
const n=5;
var
a:array[1..n,1..n] of integer;
i,j,s,k:integer;
begin
Randomize;
writeln('Исходный массив:');
for i:=1 to n do
begin
for j:=1 to n do
begin
a[i,j]:=random(100)-50;
write(a[i,j]:4);
end;
writeln;
end;
s:=0; k:=0;
for i:=1 to n do
for j:=1 to i-1 do
if a[i,j]>0 then begin s:=s+a[i,j]; k:=k+1; end;
writeln('s = ',s,' k = ',k);
end.
Пример:
Исходный массив:
29 29 -6 39 -2
-8 40 9 22 -8
-44 4 45 39 -47
26 -48 23 -25 -16
39 13 -19 -29 -35
s = 105 k = 5