Вопрос задан 21.08.2018 в 14:29. Предмет Информатика. Спрашивает Кобляков Женя.

Срочно... Дан массив s из n чисел, значения элементов которых находится на интервале от 0 до 400.

Заменить все четные элементы стоящие на нечетных местах на противоположные.
0 0
Перейти к ответам

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

Внимание! Ответы на вопросы дают живые люди. Они могут содержать ошибочную информацию, заблуждения, а также ответы могут быть сгенерированы нейросетями. Будьте внимательны. Если вы уверены, что ответ неверный, нажмите кнопку "Пожаловаться" под ответом.
Отвечает Матвеева Алина.
Const n=10;
var s:array[1..n] of integer;
i:integer;
begin
Randomize;
writeln('Массив A:');
for i:=1 to n do
 begin
 s[i]:=random(401);
 write(s[i]:5);
 end;
writeln;
p:=1;
for i:=1 to n do
 if (s[i] mod 2=0)and(i mod 2<>0)
  then s[i]:=-s[i];
writeln('Измененный массив:');
for i:=1 to n do write(s[i]:5);
writeln;
end.

Пример:
Массив A:
 75 55 240 33 312 98 126 88 161 123
Измененный массив:
 75 55 -240 33 -312 98 -126 88 161 123
0 0
Отвечает нейросеть ChatGpt. Будьте внимательны, ответы нейросети могут содержать ошибочные или выдуманные данные.

Modifying Array Elements Based on Position and Parity

To solve the given problem, we need to perform the following steps: 1. Iterate through the array. 2. Check if the current element is even and its position is odd. 3. If the conditions are met, replace the element with its opposite value.

Here's a Python code snippet to achieve this:

```python def modify_array(arr): for i in range(len(arr)): if i % 2 != 0 and arr[i] % 2 == 0: arr[i] = -arr[i] return arr ```

In this code: - We iterate through the array using a for loop. - We use the index `i` to check if the position is odd (`i % 2 != 0`) and if the element is even (`arr[i] % 2 == 0`). - If both conditions are met, we replace the element with its opposite value by negating it (`arr[i] = -arr[i]`).

You can use this `modify_array` function to modify the given array `s` as per the requirements.

Let me know if you need further assistance with this!

0 0

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

Последние заданные вопросы в категории Информатика

Задать вопрос