var a: array[1..n1, 1..m1] of integer; b: array[1..m1] of integer; i, j, m, n: integer;
begin Write('Введите через пробел число строк и столбцов массива: '); Readln(n, m); Randomize; Writeln('Исходный массив'); for i := 1 to n do begin for j := 1 to m do begin a[i, j] := Random(101) - 50; Write(a[i, j]:4) end; Writeln end; Writeln('Сформированный массив'); for j := 1 to m do begin i := 1; while (i <= n) and (a[i, j] >= 0) do i := i + 1; if i <= n then b[j] := a[i, j] else b[j] := -99; Write(b[j]:4) end; Writeln end.
1) var i, max, maxin: smallint; arr1, arr, sum: array[1..25] of smallint;
begin max := -(MaxSmallInt); randomize(); for i := 1 to 25 do begin arr[i] := Random(-100, 100); arr1[i]:=arr[i]; write(arr[i], ' '); while arr[i] <> 0 do begin sum[i] := abs(arr[i] mod 10) + sum[i]; arr[i] := arr[i] div 10; if sum[i] > max then begin max := sum[i]; maxin:=i; end; end; end; writeln(); writeln(arr1[maxin]); end.
2) var i, sum: byte; arr: array[1..20] of byte;
begin sum := 0; randomize(); for i := 1 to 20 do begin arr[i] := random(10); write(arr[i], ' '); if arr[i] = i then sum := i + sum; end; writeln(); writeln(sum); end.
n1 = 20;
m1 = 20;
var
a: array[1..n1, 1..m1] of integer;
b: array[1..m1] of integer;
i, j, m, n: integer;
begin
Write('Введите через пробел число строк и столбцов массива: ');
Readln(n, m);
Randomize;
Writeln('Исходный массив');
for i := 1 to n do
begin
for j := 1 to m do
begin
a[i, j] := Random(101) - 50;
Write(a[i, j]:4)
end;
Writeln
end;
Writeln('Сформированный массив');
for j := 1 to m do
begin
i := 1;
while (i <= n) and (a[i, j] >= 0) do i := i + 1;
if i <= n then b[j] := a[i, j] else b[j] := -99;
Write(b[j]:4)
end;
Writeln
end.
Тестовое решение:
Введите через пробел число строк и столбцов массива: 3 10
Исходный массив
-11 -18 -42 -22 -9 2 21 15 40 -3
4 -5 40 -13 -44 -37 43 47 1 -39
20 50 21 -18 -10 6 12 -10 43 -37
Сформированный массив
-11 -18 -42 -22 -9 -37 -99 -10 -99 -3
var
i, max, maxin: smallint;
arr1, arr, sum: array[1..25] of smallint;
begin
max := -(MaxSmallInt);
randomize();
for i := 1 to 25 do
begin
arr[i] := Random(-100, 100);
arr1[i]:=arr[i];
write(arr[i], ' ');
while arr[i] <> 0 do
begin
sum[i] := abs(arr[i] mod 10) + sum[i];
arr[i] := arr[i] div 10;
if sum[i] > max then begin
max := sum[i];
maxin:=i;
end;
end;
end;
writeln();
writeln(arr1[maxin]);
end.
2)
var
i, sum: byte;
arr: array[1..20] of byte;
begin
sum := 0;
randomize();
for i := 1 to 20 do
begin
arr[i] := random(10);
write(arr[i], ' ');
if arr[i] = i then sum := i + sum;
end;
writeln();
writeln(sum);
end.