/* insert an element into array */
#include<stdio.h>
#include<conio.h>
void main()
{
int a[10],i,k,n,x,p;
printf("\n enter the size");
scanf("%d",&n);
printf("\n enter the elements");
for(i=0;i<n;i++)
scanf("%d",&a[i]);
printf("\n enter the element to be inserted");
scanf("%d",&x);
printf("\n enter the position");
scanf("%d",&p);
n++;
for(k=n;k<n;k++)
{
a[k]=a[k-1];
a[p]=x;
}
printf("\after insert element");
for(i=0;i<n;i++)
printf("%d",a[i]);
getch();
}
No comments:
Post a Comment