Delete Duplicate Elements in Array

Advertisements

Prev Tutorial Next Tutorial

Delete Duplicate Elements in an Array in C

Array is collection of similar data type, In this code we enter only Integer type values and remove all duplicate value form array list. To delete all duplicate elements from array list you need looping and if else statement.

delete duplicate array element

C Program to Remove Duplicate Elements in an Array

#include<stdio.h>
#include<conio.h>

void main()
{
 int arr[20], i, j, k, size;
 
   printf("\nEnter Size of an Array : ");
   scanf("%d", &size);
 
   printf("\nEnter any %d Numbers : ",size);
   for (i = 0; i < size; i++)
      scanf("%d", &arr[i]);
 
   printf("\nArray with Unique list  : ");
   for (i = 0; i < size; i++) 
   {
      for (j = i + 1; j < size;)
	  {
         if (arr[j] == arr[i])
		 {
            for (k = j; k < size; k++)
			{
               arr[k] = arr[k + 1];
            }
            size--;
         }
		 else
            j++;
      }
   }
 
   for (i = 0; i < size; i++) 
   {
      printf("%d ", arr[i]);
   }
getch();
}

Output

Enter Size of an Array : 5
Enter any 5 Numbers : 3 1 4 6 4
Array with Unique list  : 3 1 4 6 

Prev Tutorial Next Tutorial

Google Advertisment

Buy This Ad Space @$20 per Month, Ad Size 600X200 Contact on: hitesh.xc@gmail.com or 9999595223

Magenet is best Adsense Alternative here we earn $2 for single link, Here we get links ads. Magenet

For Projects 9999595223

Google Advertisements


Buy Websites 9999595223

Buy College Projects with Documentation Contact on whatsapp 9999595223. Contact on: hitesh.xc@gmail.com or 9999595223 Try this Keyword C++ Programs

Advertisements