You are on page 1of 1

// array element insertion program

#include<stdio.h>

int main()
{
int a[10]={1,2,4,5,6};
int k;
int p;
int i;
int N=5;

printf("\nArray elements before insertion");


for(i=0;i<N;i++)
{
printf("%d\n",a[i]);
}

printf("Enter the position of array element: ");


scanf("%d",&p);

printf("\nEnter the array element: ");


scanf("%d",&k);

for(i=N;i>=p;i--)
{
a[i+1]=a[i]; // extending the position of array elements by 1
}

a[p]=k; // assigning array element to its location

N++;
printf("\nArray elements after insertion: ");
for(i=0;i<N;i++)
{
printf("%d\n",a[i]); // displaying array elements
}
return 0;
}

You might also like