
Программирование.Паскаль.Массивы1)Дан массив Р(15).Найти сумму всех отрицательных элементов с
четными индексами.Полученный результат вывести на экран.2)Ввести с пульта оператора массив МАС1 семь целых чисел. Переписать из МАС1 в МАС2 элементы значения которых положительные,в МАС3 элементы значения которых отрицательные. На пульт оператора вывести значения МАС1,МАС2,МАС3

Ответы на вопрос

const n=15;
var P:array[1..15]of real;
i:integer;
s:real;
begin
s:=0;
for i:=1 to n do
begin
read(p[i]);
if(i mod 2=0)and(p[i]<0)then s:=s+p[i];
end;
writeln(s);
end.
2)
program gt;
uses crt,graphabc;
const n=7;
var mac1,mac2,mac3:array[1..15]of real;
i,k1,k2:integer;
begin
k1:=0;k2:=0;
for i:=1 to n do
begin
read(mac1[i]);
if(mac1[i]>0)then begin
Inc(k1);
mac2[k1]:=mac1[i];
end;
if(mac1[i]<0)then begin
Inc(k2);
mac3[k2]:=mac1[i];
end;
end;
for i:=1 to n do
write(mac1[i],' ');
writeln;
for i:=1 to k1 do
write(mac2[i],' ');
writeln;
for i:=1 to k2 do
write(mac3[i],' ');
end.



Task 1: Finding the sum of negative elements with even indices in an array
To find the sum of all negative elements with even indices in an array, you can follow these steps:
1. Declare an array `P` with a size of 15. 2. Initialize the array `P` with random integer values. 3. Initialize a variable `sum` to 0 to store the sum of the negative elements with even indices. 4. Iterate over the array `P` using a loop. 5. Check if the current element is negative and if its index is even. 6. If both conditions are true, add the element to the `sum`. 7. After the loop, display the value of `sum` on the screen.
Here's an example code snippet in Pascal that implements the above steps:
```pascal program SumOfNegativeElements;
var P: array[1..15] of Integer; sum: Integer; i: Integer;
begin sum := 0;
// Initialize the array P with random values for i := 1 to 15 do P[i] := Random(100) - 50;
// Calculate the sum of negative elements with even indices for i := 2 to 15 step 2 do begin if P[i] < 0 then sum := sum + P[i]; end;
// Display the result writeln('The sum of negative elements with even indices is: ', sum);
end. ```
Please note that the above code generates random values for the array `P`. If you have specific values for the array, you can modify the code accordingly.
Task 2: Copying positive and negative elements to different arrays
To copy the positive elements to one array (`MAS2`) and the negative elements to another array (`MAS3`), you can follow these steps:
1. Declare three arrays: `MAS1`, `MAS2`, and `MAS3`, each with a size of 7. 2. Initialize the array `MAS1` with values entered by the operator. 3. Iterate over the array `MAS1` using a loop. 4. Check if the current element is positive or negative. 5. If the element is positive, copy it to the array `MAS2`. 6. If the element is negative, copy it to the array `MAS3`. 7. After the loop, display the values of `MAS1`, `MAS2`, and `MAS3` on the screen.
Here's an example code snippet in Pascal that implements the above steps:
```pascal program CopyPositiveAndNegativeElements;
var MAS1: array[1..7] of Integer; MAS2: array[1..7] of Integer; MAS3: array[1..7] of Integer; i: Integer;
begin // Input values for MAS1 from the operator writeln('Enter 7 integer values for MAS1:'); for i := 1 to 7 do begin write('Value ', i, ': '); readln(MAS1[i]); end;
// Copy positive and negative elements to MAS2 and MAS3 for i := 1 to 7 do begin if MAS1[i] > 0 then MAS2[i] := MAS1[i] else if MAS1[i] < 0 then MAS3[i] := MAS1[i]; end;
// Display the values of MAS1, MAS2, and MAS3 writeln('MAS1: '); for i := 1 to 7 do write(MAS1[i], ' '); writeln;
writeln('MAS2: '); for i := 1 to 7 do write(MAS2[i], ' '); writeln;
writeln('MAS3: '); for i := 1 to 7 do write(MAS3[i], ' '); writeln;
end. ```
Please note that the above code assumes that the operator will enter 7 integer values for `MAS1`. You can modify the code accordingly if you have a different number of elements.


Топ вопросов за вчера в категории Информатика







Последние заданные вопросы в категории Информатика
-
Математика
-
Литература
-
Алгебра
-
Русский язык
-
Геометрия
-
Английский язык
-
Химия
-
Физика
-
Биология
-
Другие предметы
-
История
-
Обществознание
-
Окружающий мир
-
География
-
Українська мова
-
Информатика
-
Українська література
-
Қазақ тiлi
-
Экономика
-
Музыка
-
Право
-
Беларуская мова
-
Французский язык
-
Немецкий язык
-
МХК
-
ОБЖ
-
Психология
-
Физкультура и спорт
-
Астрономия
-
Кыргыз тили
-
Оʻzbek tili