C Exercises: Count the total number of duplicate elements in an array
5. Count Duplicate Elements
Write a program in C to count the total number of duplicate elements in an array.
The task involves writing a C program to count the number of duplicate elements in an array. The program will take a specified number of integer inputs, store them in an array, and then determine and display how many elements appear more than once.
Visual Presentation:

Pseudo code to count the total number of duplicate elements in an array:
- Initialize a variable 'count' to 0.
- Read the array size, 'n'.
- Declare an integer array of size 'n'.
- Read the array elements.
- Loop through each element of the array from index 0 to n-2: a. Loop through the remaining elements of the array from index i+1 to n-1: i. If the current element and any of the remaining elements are equal, increment the 'count' variable and break out of the inner loop.
- Print the value of 'count' as the total number of duplicate elements in the array.
- End
Sample Solution:
C Code:
Sample Output:
Input the number of elements to be stored in the array :5 Input 5 elements in the array : element - 0 : 1 element - 1 : 1 element - 2 : 2 element - 3 : 3 element - 4 : 3 Total number of duplicate elements found in the array: 2
Flowchart:

For more Practice: Solve these Related Problems:
- Write a C program to count the number of duplicate elements in an array without using additional arrays.
- Write a C program to list duplicate elements along with their frequency from an array.
- Write a C program to identify the first duplicate element encountered in an array.
- Write a C program to count duplicates using a hash table approach with dynamic memory allocation.
Go to:
PREV : Array Copy.
NEXT : Print Unique Elements.
C Programming Code Editor:
Have another way to solve this solution? Contribute your code (and comments) through Disqus.
What is the difficulty level of this exercise?
Test your Programming skills with w3resource's quiz.