Welcome to collectivesolver - Programming & Software Q&A with code examples. A website with trusted programming answers. All programs are tested and work.

Contact: aviboots(AT)netvision.net.il

Buy a domain name - Register cheap domain names from $0.99 - Namecheap

Scalable Hosting That Grows With You

Secure & Reliable Web Hosting, Free Domain, Free SSL, 1-Click WordPress Install, Expert 24/7 Support

Semrush - keyword research tool

Boost your online presence with premium web hosting and servers

Disclosure: My content contains affiliate links.

39,845 questions

51,766 answers

573 users

How to insert an element at a specific index in an array with Pascal

1 Answer

0 votes
program InsertElementInArray;

type
  TArray = array[1..100] of Integer;

var
  arr: TArray;
  size, i, index, val: Integer;

begin
  { Initialize the array and its size }
  size := 5;
  arr[1] := 7;
  arr[2] := 6;
  arr[3] := 9;
  arr[4] := 1;
  arr[5] := 4;

  { Specify the index and value to insert }
  index := 3;
  val := 100;

  { Shift elements to the right }
  for i := size downto index do
    arr[i + 1] := arr[i];

  { Insert the new element }
  arr[index] := val;

  { Increase the size of the array }
  size := size + 1;

  for i := 1 to size do
    Write(arr[i], ' ');
end.

 
 
(*
run:
 
7 6 100 9 1 4 
 
*)

 



answered Feb 20, 2025 by avibootz
...