thestudent 0 Newbie Poster
#include<iostream.h>
#include<conio.h>
int lsearch(int[],int,int);
int main()
{
    int ar[50],n,item,index;
    cout<<"enter the size";
    cin>>n;
    cout<<"enter the array\n";
    for(int i=0;i<n;i++)
    cin>>ar[i];
    char ch ='y';
    while (ch=='y')
    {
    cout<<"enter the no. to be deleted\n";
    cin>>item;
    index=lsearch(ar,n,item);
    if(index!=-1)
    ar[index]=0;
    else
    {cout<<"sorry!no such element found";}
    cout<<"the deleted element is shown as (0)\n";
    for(int i=0;i<n;i++)
    cout<<ar[i]<<"\n";
    cout<<"after shifting\n";
    for(int i=0;i<n;i++)
    {
        ar[i]=ar[i+1];
    }
    n-=1;
    cout<<"\n";
    cout<<"want to delete more\n";
    cin>>ch;
    }
    cout<<"the new array is\n";
    for(int i=0;i<n;i++)
    cout<<ar[i]<<" ";
    getch();
}
int lsearch(int ar[],int size,int item)
{
    for(int i=0;i<size;i++)
    {
                       if(ar[i]==item) 
                       return i;
                       }
                       return -1;
                       }

SO HERE IS THE CODE THAT I HAVE WRITTEN FOR DELETION USING ARRAYS....
THOUGH THE OUTPUT IS COMING BUT THERE IS A PROBLEM WITH THAT
WHEN THE LINE"the new array is"HAS COME THE COMPILER IS NOT SHOWING THE FIRST ELEMENT...AND THE (0) FOR THE DELETED ELEMENT IS ALSO COMING.......WHICH ACCORDING TO ME SHOULD NOT COME
THANX FOR ANY HELP:)

Be a part of the DaniWeb community

We're a friendly, industry-focused community of developers, IT pros, digital marketers, and technology enthusiasts meeting, networking, learning, and sharing knowledge.