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