WAP to insert element into array
#include<iostream.h>
#include<conio.h>
#include<math.h>
void main()
{
int i,loc,n,new1,a[20];
cout<<"\n enter size of array :";
cin>>n;
cout<<"\n enter element of array :";
for(i=1;i<=n;i++)
cin>>a[i];
cout<<"\n enter element is to be insert :";
cin>>new1;
cout<<"\n enter location where element is insert :";
cin>>loc;
i=n;
while(i>=loc)
{
a[i+1]=a[i];
i--;
}
a[loc]=new1;
n++;
cout<<"\n The result is :";
for(i=1;i<=n;i++)
cout<<" "<<a[i];
getch();
clrscr();
}
/* output
enter size of array :5
enter element of array :11 62 45 78 12
enter element is to be insert :33
enter location where element is insert :3
The result is : 11 62 33 45 78 12
No comments:
Post a Comment