//insertion in a 1D array
#include<iostream.h>
#include<conio.h>
main()
{
int i,n,a[10],loc,k;
cout<<"Enter No of elements in array";
cin>>n;
cout<<"Enter elements";
for(i=1;i<=n;i++)
{
cin>>a[i];
}
cout<<"Enter Element to Insert and Place";
cin>>k>>loc;
for(i=n;i>=loc;i--)
{
a[i+1]=a[i];
}
a[loc]=k;n=n+1;
for(i=1;i<=n;i++)
cout<<a[i]<<endl;
getch();
}
#include<iostream.h>
#include<conio.h>
main()
{
int i,n,a[10],loc,k;
cout<<"Enter No of elements in array";
cin>>n;
cout<<"Enter elements";
for(i=1;i<=n;i++)
{
cin>>a[i];
}
cout<<"Enter Element to Insert and Place";
cin>>k>>loc;
for(i=n;i>=loc;i--)
{
a[i+1]=a[i];
}
a[loc]=k;n=n+1;
for(i=1;i<=n;i++)
cout<<a[i]<<endl;
getch();
}
No comments:
Post a Comment