This article talks about the program that eliminates duplicate elements from an array. Duplicate elements are those that appear more than once in a given array, they can be observed in both sorted and unsorted arrays. In order to create an array that only contains unique elements, we need to remove any duplicate elements.
Input: arr = {1, 2, 3, 4, 4}
Output: arr = {1, 2, 3, 4}
Input: arr = {9, 2, 7, 4, 7}
Output: arr = {9, 2, 7, 4}
@@coding::1@@
The following is the program used to remove duplicate elements in a sorted array using pointers
//Code using pointers n#include<stdio.h>n#include<stdlib.h>nint i,j;nint removed(int*,int);nint main()n{nint n,*a;nscanf(“%dâ€,&n);na=(int*)malloc(n*sizeof(int));nfor(i=0;i<n;i++)nscanf(“%dâ€,(a+i));nremoved(a,n);nreturn 0;n}nint removed(int*a,int n)n{nint k;nfor(i=0;i<n;i++)n{nfor(j=i+1;j<n;)n{nif(*(a+i)==*(a+j))n{nfor(k=j;k<n;k++)n{n*(a+k)==*(a+k+1);n}nn–;n}nelsenj++;n}n}nfor(i=0;i<n;i++)nprintf(“%dnâ€,*(a+i));nreturn 0;n}n
@@coding::2@@