Count total duplicate elements in array

Write a program to count total duplicate elements in array. If the element is present in array then how many times otherwise not.


Source Code:

#include<stdio.h>
#include<conio.h>
void main()
{
	int a[10],x,i,y=0;
	clrscr();
	for(i=0;i<10;i++)
	{
		printf("Enter the array element=");
		scanf("%d",&a[i]);
	}
	printf("Enter the number=");
	scanf("%d",&x);
	for(i=0;i<10;i++)
	{
		if(x==a[i])
		{
			y++;
		}
	}
	if(y>0)
	{
		printf("The number exist");
		printf("\nThe number is repeated %d times",y);
	}
	else
	{
		printf("The number doesn't exist");
	}
	getch();
}

Output:

Enter array element: 1
Enter array element: 2
Enter array element: 5
Enter array element: 2
Enter array element: 5
Enter array element: 2
Enter array element: 3
Enter array element: 5
Enter array element: 6
Enter array element: 10

Enter the number=5
The number exist
The number is repeated 3 times

Leave a Reply

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