Question: remove an element
Given an array and a number (this number is not necessarily in the array), delete this number from the array and return the remaining array length.
For example: A [] = {1, 2, 3, 4, 5}. to delete the number 3, the returned array length is 4.
Dear friends, is the question very simple?
Tip: int removeelement (int A [], int N, int ELEM)
N indicates the length of the array, and ELEM indicates the elements to be deleted.
Format:
Enter N, an array a [n], an ELEM element to be deleted, and an index of the remaining array length is returned.
Sample Input
23 33
Sample output
0
Answer:
#include <stdio.h>int removeElement(int A[], int n, int elem);int main(){ int n,A[100],elem,i;scanf("%d",&n);for(i = 0;i < n;i++){scanf("%d",&A[i]);}scanf("%d",&elem);i = removeElement(A,n,elem);printf("%d\n",i);return 0;}int removeElement(int A[], int n, int elem){int i,count = 0;for(i = 0;i < n;i++){if(A[i] == elem){A[i] = "";count++;}}return (n-count);}
If you cannot understand it, please leave a message or leave an email !!! O (partition _ partition) O
Question: remove an element