insert delete an element from array

#include<iostream.h>
#include<conio.h>
void main()
{
clrscr();
int n,x,c=0,e,ch,i,a[50],j;
cout<<“Enter Array lim”<<endl;
cin>>n;
cout<<“Enter array”<<endl;
for(i=0;i<n;i++)
cin>>a[i];
cout<<“Enter Choice 1:Deletion 2Insertion”<<endl;
cin>>ch;
switch(ch)
{
case 1:
cout<<“Enter to be deleted”<<endl;
cin>>x;
for(i=0;i<n;i++)
{

if(a[i]==x)
{c++;
for(j=i;j<n;j++)
{
a[j]=a[j+1];
}
}
}
if(c==0)
cout<<“ENP”<<endl;
for(i=0;i<n-c;i++)
cout<<a[i]<<endl;
break;

case 2:
cout<<“Enter What & Where to be inserted”<<endl;
cin>>e>>x;
for(i=n;i>=x;i–)
a[i]=a[i-1];
a[x-1]=e;
for(i=0;i<=n;i++)
cout<<a[i]<<endl;
break;
}
getch();
}

Advertisements

Leave a Reply

Fill in your details below or click an icon to log in:

WordPress.com Logo

You are commenting using your WordPress.com account. Log Out / Change )

Twitter picture

You are commenting using your Twitter account. Log Out / Change )

Facebook photo

You are commenting using your Facebook account. Log Out / Change )

Google+ photo

You are commenting using your Google+ account. Log Out / Change )

Connecting to %s