Posted By:
23 Jun, 2013 1:07 pm PDT

Delete an element from arrays in c

How to delete a given element from a given array?
Attachment:None


First the user is asked to input an array of elements and then also asked to input the element to be deleted. That element is searched among the whole array and when found it is removed and the new array is displayed. The code which finds the element and overwrites that element is

for(k=0;k<n;k++)

{ if(a[k] == d) loc = k; }

 

for(i=loc;i<=n-1;i++) a[i] = a[i+1];

d is the element to be deleted and loc is the location where d is located in the array. Please see the video for more details

Was it useful?  




Please login to reply to this problem.