
Напишите программу в паскале: удалить из массива последний четный элемент


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

Const
n=5;
Var
ar:array[1..n] of integer;
i,indf:integer;
begin
indf:=-1;
for i:=1 to n do
begin
readln(ar[i]);
if not(odd(ar[i])) then indf:=i;
end;
if indf=-1 then
writeln('Нет чётных')
else
begin
for i:=indf to n-1 do
ar[i]:=ar[i+1];
for i:=1 to n-1 do
write(ar[i]:4);
end;
end.
Пример ввода:
1 2 3 4 5
Пример вывода:
1 2 3 5



Program in Pascal to Remove the Last Even Element from an Array
To achieve this, we can write a program in Pascal that iterates through the array and removes the last even element it encounters. Here's a sample program to accomplish this task:
```pascal program RemoveLastEvenElement;
const MAX = 100;
var arr: array[1..MAX] of integer; n, i, lastEvenIndex: integer;
begin { Input the size of the array } write('Enter the number of elements in the array: '); readln(n);
{ Input the elements of the array } writeln('Enter the elements of the array:'); for i := 1 to n do begin write('Element ', i, ': '); readln(arr[i]); end;
{ Find and remove the last even element } lastEvenIndex := 0; for i := 1 to n do begin if (arr[i] mod 2 = 0) then lastEvenIndex := i; end;
if (lastEvenIndex <> 0) then begin for i := lastEvenIndex to n - 1 do arr[i] := arr[i + 1]; n := n - 1; end;
{ Output the modified array } writeln('The modified array after removing the last even element:'); for i := 1 to n do write(arr[i], ' '); end. ```
This program first takes the input of the array elements, then iterates through the array to find the last even element and removes it. Finally, it outputs the modified array after the removal.
Let me know if you need further assistance with this program or anything else!


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







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