Sunday, August 21, 2011

How to remove an element in array using C++.

//How to remove an element in array using C++.
#include<iostream.h>
#include<conio.h>
void main()
{
 int i, k, j, item, data[50], n;
 clrscr();
 cout<<"Enter the number of elements in the array:";
 cin>>n;
 cout<<endl<<"Enter the value of "<<n<<" elements:";
 for(i=0; i<n; i++)
 {
  cin>>data[i];
 }
 cout<<endl<<" Enter the location of item to be deleted:";
 cin>>k;
 for(j=k;j<n-1; j++)
 {
  data[j]=data[j+1];
 }
 n=n-1;
 for(i=0;i<n;i++)
 {
  cout<<endl<<i<<" element is:"<<data[i];
 }
 getch();
}

Previous Next Home
0 Comments
Comments

Leave a Comment

:)) ;)) ;;) :D ;) :p :(( :) :( :X =(( :-o :-/ :-* :| 8-} :)] ~x( :-t b-( :-L x( =))

Twitter Delicious Facebook Favorites More