Q
Q
quintbrut2020-01-22 11:44:29
Pascal
quintbrut, 2020-01-22 11:44:29

How to remove an element from an array by index?

There is

The code
program akb;
procedure DeleteElem<T>(a: array of T; k: word); 
begin 
for var i := k - 1 to length(a) - 2 do 
a[i] := a[i + 1]; 


SetLength(a, length(a) - 1); 

for var i := 0 to length(a) - 1 do 
write(a[i] + ' '); 

end; 

var
  text:string;
  k:integer;

begin 
  
  write ('Введите текст: ');
  readln(text);
  
  var arr := text.Split(' '); // Строка разбита на слова по пробелам
  //writeln(arr[0], ' ', arr[3]); // Слово11 Слово22
  write ('Введите элемент который нужно удалить: ');
  readln(k);


writeln('Массив после обработки: '); 
DeleteElem(arr, k); 
end.
.
Everything is fine on pascal ABC
works
5e280ab68e183732947485.png
.
But I need to run it on Turbo Pascal and this is what is there
coming out
5e280afc6c597154987970.png

I need it to work on turbo pascal, what needs to be changed in the code?
Initial task.
Дан текст не более 255 символов. Слова отделяются друг от друга пробелами. Удалить из текста слова с указанными номерами.

Answer the question

In order to leave comments, you need to log in

1 answer(s)
H
HemulGM, 2020-01-22
@quintbrut

You initialize a variable at once in a cycle. TP can't do that.
Well, judging by the assignment, do not forget that your words are shifted and the indexes of the words will not match.

Didn't find what you were looking for?

Ask your question

Ask a Question

731 491 924 answers to any question