PROGRAM TO DELETE ANY ELEMENT FROM AN ARRAY.
#include <iostream>
using namespace std;
int main()
{
int a[100],index,size,i,num;
cout<<"Enter Size of Array: ";
cin>>size;
cout<<"\nEnter "<<size<<" Array Elements: ";
for(i=0;i<size;i++)
cin>>a[i];
cout<<"\nEnter Element to be Deleted: ";
cin>>num;
for(i=0;i<size;i++)
{
if(a[i]==num)
{
index=i;
break;
}
}
for(i=index;i<size;i++)
{
a[i]=a[i+1];
}
cout<<"\nArray after Deletion is:\n";
for(i=0;i<size-1;i++)
cout<<a[i]<<" ";
return 0;
}
#include <iostream>
using namespace std;
int main()
{
int a[100],index,size,i,num;
cout<<"Enter Size of Array: ";
cin>>size;
cout<<"\nEnter "<<size<<" Array Elements: ";
for(i=0;i<size;i++)
cin>>a[i];
cout<<"\nEnter Element to be Deleted: ";
cin>>num;
for(i=0;i<size;i++)
{
if(a[i]==num)
{
index=i;
break;
}
}
for(i=index;i<size;i++)
{
a[i]=a[i+1];
}
cout<<"\nArray after Deletion is:\n";
for(i=0;i<size-1;i++)
cout<<a[i]<<" ";
return 0;
}