C Program to Find Out the Duplicate Elements in Array

This program takes the size of the array as input and then takes input for each element of the array. The findDuplicates function is responsible for finding and printing the duplicate elements. It uses nested loops to compare each element with every other element in the array and prints the duplicates.Keep in mind that this program assumes that the array has integers as its elements. Additionally, it finds and prints duplicates without considering the order of appearance in the array. If you need a more specific solution, you may need to adjust the code accordingly.

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.

Shopping Basket
Verified by MonsterInsights