Skip to main content

PROGRAM TO DELETE ELEMENT OF ARRAY

 #include<iostream>

using namespace std;

int main()

{

int n,m,temp,count=0;

  cout<<"Enter size of array:-\t";

cin >>n;

int arr[n];

  cout<<"Enter elements of array:-\t";

for (int i = 0; i < n; i++)

cin >> arr[i];

  cout<<"Enter element of array you want to delete:-\t";

  cin>>m;

  for(int i=0;i<n;i++)

    { 

      count+=1;

      if(arr[i]==m)

        for(int j=count;j<n;j++)

            arr[j-1]=arr[j];

    }

  cout<<"New Array is :-\t";

  for(int i = 0; i < n-1; i++)

cout<< arr[i]<<" ";

}


Comments