//Insertion in Array
#include<stdio.h>
#include<conio.h>
void main()
{
int
a[30],v,n,i,loc;
clrscr();
printf("\nEnter no of elements :");
scanf("%d",&n);
for(i=0;i<n;i++)
{
scanf("%d",&a[i]);
}
printf("\nEnter the element to be inserted :");
scanf("%d",&v);
printf("\nEnter the location");
scanf("%d",&loc);
//Create space at the specified location
for(i=n;i>=loc;i--)
{
a[i]=a[i-1];
}
n++;
a[loc-1]=v;
//Print out the result of insertion
for(i=0;i<n;i++)
printf("\n%d",a[i]);
getch();
}
No comments:
Post a Comment
Note: only a member of this blog may post a comment.