C Program to Find Duplicate Elements in Array


Prev Tutorial Next Tutorial

Find Duplicate Elements in Array in C

Array is the collection of similar data type, In this program we find duplicate elements from an array, Suppose array have 3, 5, 6, 11, 5 and 7 elements, in this array 5 appeare two times so this is our duplicate elements.

Find Duplicate Elements in Array in C

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

 void main()
 {
  int i,arr[20],j,no;
  clrscr();
  printf("Enter size of array: ");
  scanf("%d",&no);
  printf("Enter any %d elements in array: ",no);
  for(i=0;i<no;i++)
  {
   scanf("%d",&arr[i]);
  }
  printf("Duplicate elements are: ");
  for(i=0; i<no; i++)
   {
    for(j=i+1;j<no;j++)
    {
    if(arr[i]==arr[j])
    {
    printf("%d\n",arr[i]);
    }
   }
   }
  getch();
 }

Output

Enter size of Array : 5
Enter any 5 elements in array: 
5 4 5 2 3 
Duplicate elements are: 
5

Prev Tutorial Next Tutorial



Download Projects

Advertisements

FREE Online Google Play APK Downloader

Buy APP Installs, Buy 100% Genuine Installs