var x: array[1..n] of integer; i, min, max: integer;
begin Randomize; Writeln('Элементы массива'); min := 32767; max := -32768; for i := 1 to n do begin x[i] := Random(101) - 50; Write(x[i]:4); if (x[i] > 0) and (min > x[i]) then min := x[i] else if (x[i] < 0) and (max < x[i]) then max := x[i] end; Writeln; Writeln('Min=', min, ', max=', max) end.
var x: array[1..n] of integer; i, max, max1: integer;
begin Randomize; Writeln('Элементы массива'); max := -32768; max1 := max; for i := 1 to n do begin x[i] := Random(100); Write(x[i]:3); if max < x[i] then begin max1 := max; max := x[i] end else if max1 < x[i] then max1 := x[i] end; Writeln; Writeln('Второй максимум равен ', max1) end.
var x: array[1..n] of integer; i, min, max: integer;
begin Randomize; Writeln('Элементы массива'); min := 32767; max := -32768; for i := 1 to n do begin x[i] := Random(101) - 50; Write(x[i]:4); if (x[i] > 0) and (min > x[i]) then min := x[i] else if (x[i] < 0) and (max < x[i]) then max := x[i] end; Writeln; Writeln('Min=', min, ', max=', max) end.
var x: array[1..n] of integer; i, max, max1: integer;
begin Randomize; Writeln('Элементы массива'); max := -32768; max1 := max; for i := 1 to n do begin x[i] := Random(100); Write(x[i]:3); if max < x[i] then begin max1 := max; max := x[i] end else if max1 < x[i] then max1 := x[i] end; Writeln; Writeln('Второй максимум равен ', max1) end.
n = 15;
var
x: array[1..n] of integer;
i, min, max: integer;
begin
Randomize;
Writeln('Элементы массива');
min := 32767; max := -32768;
for i := 1 to n do
begin
x[i] := Random(101) - 50;
Write(x[i]:4);
if (x[i] > 0) and (min > x[i]) then min := x[i]
else
if (x[i] < 0) and (max < x[i]) then max := x[i]
end;
Writeln;
Writeln('Min=', min, ', max=', max)
end.
Тестовое решение:
Элементы массива
29 -28 -14 -46 -22 13 -6 16 24 -47 -1 39 49 47 -23
Min=13, max=-1
const
n = 15;
var
x: array[1..n] of integer;
i, max, max1: integer;
begin
Randomize;
Writeln('Элементы массива');
max := -32768; max1 := max;
for i := 1 to n do
begin
x[i] := Random(100);
Write(x[i]:3);
if max < x[i] then begin max1 := max; max := x[i] end
else
if max1 < x[i] then max1 := x[i]
end;
Writeln;
Writeln('Второй максимум равен ', max1)
end.
Тестовое решение:
Элементы массива
37 66 92 11 39 32 70 17 28 80 51 37 1 56 41
Второй максимум равен 80