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

Popular posts from this blog

example of typecasting in c

/*Type Casting in C Typecasting allows us to convert one data type into other. */ //simple example to cast int value into the float. #include <stdio.h>    int   main (){   float   f = ( float ) 9 / 4 ;     printf ( "f : %f \n " ,  f  );     return   0 ;   }