Array Deletion


Delete Values from Specific Index of Array Using C++

=======================================================================

#include<iostream>
using namespace std;
main()
{
int arr[10]={10,20,40,55,60,70,80,90};

int n=8;// n is number of element existing right now in array
int k=1;// k is the specific index number from where values to delete
    int item=arr[k];
cout<<"Array Before Deletion Of values\n\n";
for(int i=0;i<n;i++)
{
cout<<arr[i]<<" ";
}
cout<<endl<<endl;
int j=k;
while(j<n-1)
{
arr[j]=arr[j+1];
j++;
}
n--;// number of element decreases by 1
cout<<"\nArray After Deletion Of value\n\n";
for(int i=0;i<=n;i++)
{
cout<<arr[i]<<"  ";
}
}


=======================================================================

OutPut:


SHARE
    Blogger Comment
    Facebook Comment

0 comments:

Post a Comment