Element removal
Given an array and a number (the number is not necessarily in the array), delete the number from the array and return the remaining array length.
such as: a[] = {1, 2, 3, 4, 5}, to remove the number 3, the returned array length is 4.
Dear little Friends, is the topic very simple?
Hint: int removeelement (int a[], int n, int elem)
where n represents the length of the array, and Elem represents the element to be deleted.
Format:
Enter a number n, enter an array a[n], and then enter the element elem to delete, returning the remaining array length index.
1#include"iostream"2 #defineMAX 100003 using namespacestd;4 intMain ()5 {6 intN, A[max], elem, ans;7CIN >>N;8 for(inti =0; i<n; i++)9scanf"%d", &a[i]);Ten OneCIN >>Elem; AAns =N; - - for(inti =0; i<n; i++) the { - if(A[i] = =elem) - { -ans--; + } - } + Acout <<ans; at -}
Removal of the garlic guest element