C Program to Find the Duplicate Elements in an Array

To find duplicate elements in an array using a C program,you can use nested loops or hash sets. I’ll provide you with a simple example using nested loops. Here’s a sample program.

Program :

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

void main()
{
int i,arr[20],j,no;

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 :

Leave a Comment

Your email address will not be published. Required fields are marked *

Shopping Basket
Select the fields to be shown. Others will be hidden. Drag and drop to rearrange the order.
  • Image
  • SKU
  • Rating
  • Price
  • Stock
  • Availability
  • Add to cart
  • Description
  • Content
  • Weight
  • Dimensions
  • Additional information
Click outside to hide the comparison bar
Compare
Verified by MonsterInsights