Save an array element with a small condition to a new array ** just starts when 100% will work!) Save the first value in the array
Ii) save the check of another item before the saved value.
Iii) if it exists, leave the element - and check the next and save
here the code below works and you will understand better
int main() { int a[10],b[10],i,n,j=0,pos=0; printf("\n enter an value "); scanf("%d",&n); printf("\n enter a array value"); for(i=0;i<n;i++) { scanf("%d",&a[i]);//gets the arry value } for(i=0;i<n;i++) { if(check(a[i],pos,b)==0)//checks array each value its exits or not { b[j]=a[i]; j++; pos++;//count the size of new storing element } } printf("\n after updating array"); for(j=0;j<pos;j++) { printf("\n %d",b[j]); } return 0; } int check(int x,int pos,int b[]) { int m=0,i; for(i=0;i<pos;i++)//checking the already only stored element { if(b[i]==x) { m++; //already exists increment the m value } } return m; }
source share