In this article, I am going to provide you code to remove or delete dupplicate elements from a given array in C programming, so in this program we would need sorted array elements  as output, so once duplicates are deleted we show the output as sorted array.

So for example, if we have 10 elements like this "41 55 12 -10 55 88 23 12 78 90" in an array, we should have output as "-10 12 23 41 55 78 88 90" after removing duplicate of 55 and 12.

So here is the C code for removing duplicate, the below given C program will Delete the duplicate elements using single array.

``````#include <stdio.h>

int main(void)
{

int i, j, k, t, max, ar[30];
printf(" How many elements you want to enter in an array : ");
scanf("%d", &max);

printf("\n Enter %d elements one by one : \n", max);
for (i = 0; i < max; ++i)
scanf("%d", &ar[i]);

printf("\n\n The elements Before removing Duplicates are : \n");
for (i = 0; i < max; ++i)
printf("%d ", ar[i]);

//create for loop to check all elements
for (i = 0; i < max; ++i)
{
//check second element with all other elments until last element
for (j = i + 1; j < max;)
{
//if found duplicate
if (ar[j] == ar[i])
{
//remove element
for (k = j; k < max; ++k)
{
ar[k] = ar[k + 1];
}
//reduce array max element position by 1
--max;
}
else
{
j++;
}
}
}
printf("\n\n The elements After removing Duplicates in Ascending Order are : \n");
//sort elements
for (j = 0; j < max; j++)
{
for (k = j + 1; k < max; k++)
if (ar[j] > ar[k])
{
t = ar[j];
ar[j] = ar[k];
ar[k] = t;
}
printf("%d\n", ar[j]);
}
return (0);
}``````

I have explained the code using Comments,

1. We are Asking user abut how many elements we need in an array
2. Get the elements in an array
3. Loop through all elments of an array
1. initiliaze one more loop and check if same element again exists in Loop
2. If yes, remove the element
3. Reduce array size by 1
4. Sort the Array and print it.

If we run the above code, here is the output

`````` How many elements to the Array : 10

Enter 10 elements one by one :
41 55 12 -10 55 88 23 12 78 90

The elements Before removing Duplicates are :
41 55 12 -10 55 88 23 12 78 90

The elements After removing Duplicates in Ascending Order are :
-10
12
23
41
55
78
88
90``````

You might also like to read:

Infix to postfix conversion program in C using stack (With algorithm)

Radix sort algorithm & C program sample

Bubble sort algorithm in C (With sample program)