program Change;
var
n, i, j, t: Integer;
A: array of Integer;
begin
Write ('Введите четное число N: ');
ReadLn (n);
if n mod 2 = 0 then begin
SetLength (A, n);
Randomize;
for i := Low (A) to High (A) do begin
A [i] := Random (100);
Write (A [i] :3, ' ');
end;
i := 0;
while i < n do begin
t := A [i];
A [i] := A [i + 1];
A [i + 1] := t;
i := i + 2;
WriteLn;
end else
WriteLn ('Введено не четное число.');
ReadLn;
end.
program Num5;
A: array [1..5] of Integer;
i, s, iLast: Integer;
Write ('Введите ', i, ' число: ');
ReadLn (A [i]);
s := 0;
if A [i] > 0 then
s := s + A [i]
else
s := s - A [i];
iLast := -1;
for i := High (A) downto Low (A) do begin
if A [i] > 0 then begin
iLast := i;
Break;
WriteLn ('Сумма = ', s);
if iLast <> -1 then
WriteLn ('Последнее положительное значение = ', A [iLast])
WriteLn ('Положительных значений не найдено.');
program Change;
var
n, i, j, t: Integer;
A: array of Integer;
begin
Write ('Введите четное число N: ');
ReadLn (n);
if n mod 2 = 0 then begin
SetLength (A, n);
Randomize;
for i := Low (A) to High (A) do begin
A [i] := Random (100);
Write (A [i] :3, ' ');
end;
i := 0;
while i < n do begin
t := A [i];
A [i] := A [i + 1];
A [i + 1] := t;
i := i + 2;
end;
WriteLn;
for i := Low (A) to High (A) do begin
Write (A [i] :3, ' ');
end;
end else
WriteLn ('Введено не четное число.');
ReadLn;
end.
program Num5;
var
A: array [1..5] of Integer;
i, s, iLast: Integer;
begin
for i := Low (A) to High (A) do begin
Write ('Введите ', i, ' число: ');
ReadLn (A [i]);
end;
WriteLn;
s := 0;
for i := Low (A) to High (A) do begin
if A [i] > 0 then
s := s + A [i]
else
s := s - A [i];
end;
iLast := -1;
for i := High (A) downto Low (A) do begin
if A [i] > 0 then begin
iLast := i;
Break;
end;
end;
WriteLn ('Сумма = ', s);
if iLast <> -1 then
WriteLn ('Последнее положительное значение = ', A [iLast])
else
WriteLn ('Положительных значений не найдено.');
ReadLn;
end.