//Задание №1
const
m = 5;
n = 7;
var
a: array[1..m, 1..n] of integer;
i, j, s: integer;
begin
for i := 1 to m do
begin
for j := 1 to n do
begin
a[i, j] := random(21) - 10;
if (i mod 2) <> 0 then s := s + a[i, j];
write(a[i, j]:4);
end;
writeln;
end;
write('Сумма элементов на нечетных строках = ', s);
end.
Тестовое решение:
-10 2 -1 -8 -9 -1 5
2 -10 2 4 8 -6 8
0 3 2 3 -8 -10 4
3 -3 -4 2 9 -8 3
9 -4 -1 3 7 3 -2
Сумма элементов на нечетных строках = -13
//Задание №2
const
m = 5;
n = 7;
var
a: array[1..m, 1..n] of integer;
i, j, s: integer;
begin
for i := 1 to m do
begin
for j := 1 to n do
begin
a[i, j] := random(21) - 10;
if (i mod 2) <> 0 then s := s + a[i, j];
write(a[i, j]:4);
end;
writeln;
end;
writeln('Элементы на нечетных столбцах:');
for i := 1 to m do
begin
for j := 1 to n do
begin
if (j mod 2) <> 0 then write('a[', i, ',', j, '] = ', a[i, j], ' ');
end;
writeln;
end;
end.
Тестовое решение:
4 -10 -7 -4 -7 -5 -10
-1 3 6 -10 -2 -1 -5
2 8 -5 -1 -3 1 2
3 10 -5 6 -1 3 2
-8 3 4 5 -1 6 10
Элементы на нечетных столбцах:
a[1,1] = 4 a[1,3] = -7 a[1,5] = -7 a[1,7] = -10
a[2,1] = -1 a[2,3] = 6 a[2,5] = -2 a[2,7] = -5
a[3,1] = 2 a[3,3] = -5 a[3,5] = -3 a[3,7] = 2
a[4,1] = 3 a[4,3] = -5 a[4,5] = -1 a[4,7] = 2
a[5,1] = -8 a[5,3] = 4 a[5,5] = -1 a[5,7] = 10