In this tutorial, you will learn how to write C program to delete duplicate elements in an array.

Below are the approach which we will be follow to write program:

How our program will behave?

Our program will take an array as an input.

And then count the occurrence of each elements. After the count it will print only those elements as an output which has occurs only one time.

Program to remove duplicate elements from array using C

#include<stdio.h>
#include<conio.h>
#include<stdlib.h>
#define MAX 100
void nonDuplicate(int *arr,int size){
    int i,j=0;
    int ar[MAX] = {0};
    for(i=0;i<size;i++){
        ar[arr[i]]++;
        if(ar[arr[i]]==1){
            printf("%dn",arr[i]);
        }
    }
}
void main(){
    int size,i,*arr;
    printf("Please enter the array size (not max to 100) : n");
    scanf("%d", &size);
    arr=(int*)malloc(sizeof(int)*size);
    printf("please enter the array elements n");
    for(i=0; i<size; i++){
        scanf("%d",&arr[i]);
    }
    printf("After removing duplicate elements:n");
    nonDuplicate(arr, size);
    getch();    
} 

Output:

remove duplicates from array in c

Explanation of above program to remove duplicate elements from array in C

This is the logic behind removing the duplicate element of an array which has occurs more than one times using C program.

We are not removing from array, But our logic is printing element only first time.

I hope it is clear to all.