//insert delete an element from array
//Downloaded From www.c4cpp.co.nr. (C)2009.All rights reserved.
#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();
}
Programs Can Also Be Downloaded From The Folders Below....[Or Scroll Down]
Insert & Delete from Array
Click Here To Download C++ File Of This Program
Subscribe to:
Post Comments (Atom)
No comments:
Post a Comment