# Insert &Delete an element in 1-D array: C Program

0
39

## C program to insert an element in 1-D array

This code will insert an element into an array, For example consider an array a[20] having three elements in it initially and a[0] = 6, a[1] = 7 and a[2] = 9 and you want to insert a number 10 at location 1 i.e. a[0] = 10, so we have to move elements one step below so after insertion a[1] = 6 which was a[0]=10 initially, and a[2] = 7 and a[3] = 9. Array insertion does not mean increasing its size i.e array will not be containing 21 elements.

```1Program2OUTPUT3PROGRAM4OUTPUT‹›[message_box title="PROGRAM" color="yellow"]

#include <stdio.h>
#include <conio.h>

void main()
{
int array[20], position, c, n, value;
clrscr();

printf("Enter number of elements in array\n");
scanf("%d", &n);

printf("Enter %d elements\n", n);

for (c = 0; c < n; c++)
scanf("%d", &array[c]);

printf("Enter the location where you want to insert an element\n");
scanf("%d", &position);

printf("Enter the value to insert\n");
scanf("%d", &value);

for (c = n - 1; c >= position - 1; c--)
array[c+1] = array[c];

array[position-1] = value;

printf("Resultant array is\n");

for (c = 0; c <= n; c++)
printf("%d\n", array[c]);

getch();
}
[/message_box]1Program2OUTPUT3PROGRAM4OUTPUT‹›

[/sociallocker-bulk-1]

var td_screen_width = document.body.clientWidth;

if ( td_screen_width >= 1140 ) {
/* large monitors */
}

if ( td_screen_width >= 1019  && td_screen_width < 1140 ) {
/* landscape tablets */
}

```
SHARE
Previous articleUnderstanding Potentiometers
I am third year student of computer engineering in L.D COLLEGE OF ENGINEERING,Ahmedabad.