
Дан целочисленный массив размера N. Вывести все содержащиеся в данном массиве нечетные числа в
порядке возрастания их индексов.

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

Const N = 5;
Var a: Array [1..N] of Integer;
i, k: Integer;
Begin
WriteLn('Введите ', N, ' целых чисел через пробел');
For i := 1 To N Do
Read(a[i]);
For i := 1 To N Do
If a[i] Mod 2 <> 0 Then
Begin
Write(a[i], ' ');
End;
WriteLn;
ReadLn;
End.



Task Explanation
You have been given an integer array of size N. Your task is to output all the odd numbers present in the array in ascending order of their indices.
Solution
To solve this task, we can iterate through the array and check if each element is odd. If it is, we add it to a new array. Finally, we sort the new array in ascending order of indices and output the result.
Here is the step-by-step solution:
1. Create an empty array to store the odd numbers. 2. Iterate through the given array and check if each element is odd. 3. If an element is odd, add it to the new array. 4. Sort the new array in ascending order of indices. 5. Output the sorted array.
Let's implement this solution in Python:
```python def get_odd_numbers(arr): odd_numbers = [] for i in range(len(arr)): if arr[i] % 2 != 0: odd_numbers.append(arr[i]) odd_numbers.sort() return odd_numbers
# Example usage: array = [4, 3, 9, 2, 1] result = get_odd_numbers(array) print(result) ```
Output: ``` [1, 3, 9] ```
In the given example, the input array is `[4, 3, 9, 2, 1]`. The odd numbers in this array are `[3, 9, 1]`, and they are sorted in ascending order of their indices.
Please note that the code provided is a general solution and can be used for any integer array.


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