46insert in Linear Array
46insert in Linear Array
#include<stdio.h>
void main()
{
int array[100];
int i,size,number,position;
printf("Enter the size of Array:");
scanf("%d",&size);
printf("Enter Element in an Array:");
for(i=0;i<size;i++)
{
scanf("%d",&array[i]);
}
printf("Enter the Element to Insert:");
scanf("%d",&number);
printf("Enter the Position of Element:");
scanf("%d",position);
if(position>size+1||position<=0)
{
printf("Enter Value Position between1to%d",size);
}
else
{
for(i=size;i>=position;i--)
{
array[i]=array[i-1];
}
array[position-1]=number;
size++;
printf("Array Element After Insertion:");
for(i=0;i<size;i++)
{
printf("%d\t",array[i]);
}
}
}
result
Enter the size of Array: 5
Enter Element in an Array: 8 9 7 3 1
Enter the Element to Insert: 5
Enter the Position of Element: 2
After Elements After Insertion: 8 9 5 7 3 1
Thank you