Вопрос задан 23.08.2018 в 11:51. Предмет Информатика. Спрашивает Ганцгорн Александр.

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

0 0
Перейти к ответам

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

Внимание! Ответы на вопросы дают живые люди. Они могут содержать ошибочную информацию, заблуждения, а также ответы могут быть сгенерированы нейросетями. Будьте внимательны. Если вы уверены, что ответ неверный, нажмите кнопку "Пожаловаться" под ответом.
Отвечает Анарбаева Нурай.
//PascalABC.NET 3.2 сборка 1318


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
0 0
Отвечает нейросеть ChatGpt. Будьте внимательны, ответы нейросети могут содержать ошибочные или выдуманные данные.

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!

0 0

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

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

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