Pages

May 21, 2012

wap in c++ to delete an element from an array.


#include<iostream.h>
#include<conio.h>
void main()
{
clrscr();
int a[10];
int i,j,n,loc,item;
cout<<"\nEnter the no. of element\t";
cin>>n;
cout<<"\nEnter the element in array\n";
for(i=0;i<n;i++)
{
cin>>a[i];
}
cout<<"\nEnter the location from where to delete\t";
cin>>loc;
item=a[loc];


for(j=loc;j<n-1;j++)
{
a[j]=a[j+1];
}
n=n-1;
cout<<"\nDeleted element is\t"<<item<<endl;
cout<<"\nModified array is\n";
for(i=0;i<n;i++)
{
cout<<a[i]<<endl;
}
getch();
}

1 comment: