Написать программу на Pascal ABC.Дан целочисленный массив размера N. Вычислить сумму и количество положительных элементов, произведение и количество отрицательных элементов, произведение элементов до первого отрицательного. Отсортировать массив по возрастанию.
for i := 0 to N - 1 do begin write('Enter element ', i+1, ': '); readln(arr[i]);
if arr[i] > 0 then begin sumPositive := sumPositive + arr[i]; countPositive := countPositive + 1; end else if arr[i] < 0 then begin productNegative := productNegative * arr[i]; countNegative := countNegative + 1; end; if arr[i] < 0 then break else productBeforeNegative := productBeforeNegative * arr[i];
end;
// Sort the array in ascending order repeat swapped := false; for i := 0 to N - 2 do begin if arr[i] > arr[i+1] then begin temp := arr[i]; arr[i] := arr[i+1]; arr[i+1] := temp; swapped := true; end; end; until not swapped;
writeln('Sum of positive elements: ', sumPositive); writeln('Count of positive elements: ', countPositive); writeln('Product of negative elements: ', productNegative); writeln('Count of negative elements: ', countNegative); writeln('Product of elements before first negative: ', productBeforeNegative);
writeln('Sorted array:'); for i := 0 to N - 1 do write(arr[i], ' ');
program SumAndProduct;
var
arr: array of integer;
N, i, sumPositive, countPositive, productNegative, countNegative, productBeforeNegative, temp: integer;
swapped: boolean;
begin
write('Enter the size of the array: ');
readln(N);
SetLength(arr, N);
sumPositive := 0;
countPositive := 0;
productNegative := 1;
countNegative := 0;
productBeforeNegative := 1;
for i := 0 to N - 1 do
if arr[i] > 0 thenbegin
write('Enter element ', i+1, ': ');
readln(arr[i]);
begin
sumPositive := sumPositive + arr[i];
countPositive := countPositive + 1;
end
else if arr[i] < 0 then
begin
productNegative := productNegative * arr[i];
countNegative := countNegative + 1;
end;
if arr[i] < 0 then
break
else
productBeforeNegative := productBeforeNegative * arr[i];
end;
// Sort the array in ascending order
repeat
swapped := false;
for i := 0 to N - 2 do
begin
if arr[i] > arr[i+1] then
begin
temp := arr[i];
arr[i] := arr[i+1];
arr[i+1] := temp;
swapped := true;
end;
end;
until not swapped;
writeln('Sum of positive elements: ', sumPositive);
writeln('Count of positive elements: ', countPositive);
writeln('Product of negative elements: ', productNegative);
writeln('Count of negative elements: ', countNegative);
writeln('Product of elements before first negative: ', productBeforeNegative);
writeln('Sorted array:');
for i := 0 to N - 1 do
write(arr[i], ' ');
end.