Design a C program to insert an element in a specified position in the given array.
#include <conio.h>
#include<stdio.h>
display(int array[],int j)
{
int n;
for(n=0; n<j; n++)
{
printf("%d ",array[n]);
}
}
int main()
{
int array[4];
int i;
int n;
int index;
int new1;
printf("Enter items in array : ");
for(n=0; n<4; n++)
{
scanf("%d",&array[i]);
}
printf("Index must not exceed %d:",n);
scanf("%d",&index);
if(index<n)
{
printf("New item : ");
scanf("%d",&new1);
printf("Before inserting an item :");
display(array,4);
array[index]=new1;
printf("\nafter inserting an item :");
display(array,n);
}
return 0;
}
Comments
Leave a comment