C program to insert an element into the array at given location

Program in the C programming language for the insertion of an element in the array at any given location. Below is the code for the C program –

 

Logic – In this C program the array is initialized first. After the initialization process if statement is used to check if the space is still available in the array for insertion or not. If the space is not available then the program exit’s there only. But if the space is available then the program asks for the location where we want to insert the element. If the invalid location is entered then the program is terminated there. So if both the above conditions are satisfied then the insertion can be done. After insertion the new array is displayed as the output.

Input
Enter the number of elements in the array – 5
Array Elements – 23   45   2   55   91
Enter location where to insert the element – 3
Enter the element to be inserted – 111

Output
Array after insertion is – 23   45   111   2   55   91

yashan has written 70 articles

Leave a Reply

Your email address will not be published. Required fields are marked *

You may use these HTML tags and attributes: <a href="" title=""> <abbr title=""> <acronym title=""> <b> <blockquote cite=""> <cite> <code> <del datetime=""> <em> <i> <q cite=""> <s> <strike> <strong>