Q24. Write a code to delete duplicate elements from array

Delete Duplicate Elements :- In this, we will perform the delete operation in the array and after performing the delete operation, the array must contain only unique integer values.
For Example :-
Input = 5,7,8,2,4,5,6,5,4,4
Output = 5,7,8,2,4,6
So as we can see that the input consists of 10 elements ( 5,7,8,2,4,5,6,5,4,4) which contain some duplicate elements. So we have to remove duplicate elements from the array, and after performing the delete operation the output will be 5,7,8,2,4,6

Algorithm For Delete Duplicate Elements

START
Step 1 -> Input the number of elements of the array.
Step 2 -> Input the array elements.
Step 3 -> Repeat from i = 1 to n
– if (arr[i] != arr[i+1])
– temp[j++] = arr[i]
– temp[j++] = arr[n-1]
Step 4 -> Repeat from i = 1 to j
– arr[i] = temp[i]
Step 5 -> return j.
STOP

Code For Delete Duplicate Elements

Output

Array elements after deleting duplicates :5,7,8,2,4,6,

Recommended Programs
Program to find factorial of a number
Program to count number of digits in a number