C++ Program to delete a array element with a particular position

Wednesday, 20 September 2017


     #include<iostream.h>
     #include<conio.h>
     void main()
     {
     int n,a[10],i;
     int temp,j,pos;
     clrscr();
     cout<<"Enter n:\n";
     cin>>n;
     cout<<"Enter array\n";
     for(i=0;i<n;i++)
     cin>>a[i];
     cout<<"Enter position to delete element\n";
     cin>>pos;
     if(pos==n+1)
     cout<<"Deletion not possible:\n";
     else
     {
     for(i=pos-1;i<n-1;i++)
     a[i]=a[i+1];
     }
     cout<<"After deletion:\n";
     for(i=0;i<n-1;i++)
     cout<<"\n"<<a[i];
     getch();
     }

OUTPUT-

No comments:

Post a Comment

Related Posts Plugin for WordPress, Blogger...
Related Posts Plugin for WordPress, Blogger...
 

Most Reading

Labels