Repeating Elements in an array using C++
Finding all Duplicates in the given array using C++
An element in an array which is repeated more than once in the given array is called a Duplicate element.
To find the repeated elements in an array we require two loops. One will be used for array traversal and the other one is used for comparing the current element with all other elements of the array.
Sample Test Case
Enter the size of array : 5
Enter elements of array : 5 8 7 8 5
Duplicate elements : 5 8
- Declare size of array.
- Declare array.
- Input elements of the array.
- Take a for loop to traverse the whole array.
- Take another for loop to compare the current index element to all other elements after it. Note : index i should not be equal to index j.
- Print the Duplicate elements.
This page is contributed by Rishav Raj