Program to insert an element in an array at a specific position in C++ 

Program to insert an element in an array at a specific position in C++ 

In this tutorial, we will try to learn about the program of  insert an element in an array at a specific position in  C++ (C Plus Plus, CPP).

Step 1:

First of all, we need to enter the total number of elements we want to insert.

Step 2:

Enter values in elements.

Step 3:

Select the location where you want to insert the values in the elements.

Step 4:

Enter the value to insert into the element.

Step 5: 

Display result values.

Program of the insert of an element in an array at a specific position in  C++ (C Plus Plus, CPP)  

 

Output

insert of element in array at any specific position program in cpp, cplusplus, c c++ flowchart
Figure: insert of the element in an array at any specific position program in CPP, C Plus Plus, c c++ flowchart.

Video Lecture full of animations: Don’t Miss it for better Understanding

How it will works?

Now, let’s see one another example;

Program of the insert of the element in an array at a specific position in  C 

Output

insert of element in array at any specific position program in cpp, cplusplus, c c++ flowchart

Figure: insert of an element in an array at any specific position program in CPP, C Plus Plus, c c++ flowchart.


 

C Program to insert an element into the beginning of array

Algorithm of insert an element into the beginning of array

begin

IF NUMBER = MAXIMUM, return
ELSE
NUMBER = NUMBER + 1

For All Elements in A
Move to next adjacent location

T4TUTORIALS[FIRST] = New_Element

end

Output

Printing array before insertion −
T4Tutorials[0] = 6
T4Tutorials[1] = 2
T4Tutorials[2] = 1
T4Tutorials[3] = 7
Printing array after insertion −
T4Tutorials[0] = 0
T4Tutorials[1] = 6
T4Tutorials[2] = 2
T4Tutorials[3] = 1
T4Tutorials[4] = 7

Program to insert an element Before the Given Index of an Array

Algorithm of insert an element Before the Given Index of an Array

begin

IF NUMBER = MAXIMUM, return
ELSE
NUMBER = NUMBER + 1
SEEK Location index
For All Elements from T4TUTORIALS[index – 1] to T4TUTORIALS [NUMBER]
Move to next adjacent location
T4TUTORIALS [index – 1] = New_Element

end

Output

Printing array before insertion −
T4Tutorials[0] = 6
T4Tutorials[1] = 2
T4Tutorials[2] = 1
T4Tutorials[3] = 7
Printing array after insertion −
T4Tutorials[0] = 6
T4Tutorials[1] = 2
T4Tutorials[2] = 1
T4Tutorials[3] = 7
T4Tutorials[4] = 9

Topic Covered

Program of the insert of an element in an array at a specific position in  C++ (C Plus Plus, CPP)  and C with the flowchart

Subscribe for Friendship

Latest posts by Prof. Fazal Rehman Shamil (see all)

Buy advertisement space on T4Tutorials

For more details email [email protected]