The problem that I face is trying to make a program that can count how many duplicate elements are in an array. An array is a data structure that can store elements in the form of data types such as integers and strings. In order to make this program, I have to first initialize an array that the user can choose both the size of and the elements that are inside of the array. After that, I have to find a way to scan the elements inside the array, search for duplicate elements, and keep track of how many duplicate elements there are.
To get to the final solution, I first had the user input the size of the array and the elements that would be stored in the array in the form of integers. Next, I copied the size and the elements into a second array that will be used for the scan. After I had two duplicate arrays, I use a for loop with a nested for loop with a nested if statment to scan and keep track of the duplicate arrays. For each element in the 'i' for loop, the 'j' for loop checks for any elements that match with another element in the original array. If there are two elements that match, the value of the 'count' variable gets stored in a third array, then the 'count' variable gets incremented by one. After the nested for loop finishes, the 'count' variable gets reset back to '1', so that the loop later in the code does not mix anything up. After the for loop ends, it moves to another for loop with an if statement nested inside of it. This for loop scans the third array for any elements that equal '2'. The previous for loop had an if statement that makes the element in the third array equal to '2' if there is a duplicate in the original array. If any of the elements in the third array equals '2', then another variable named 'dup' gets incremented by one. 'Dup' is what will be displayed to the user to show how many of the elements in the original array are duplicates. After the last for loop runs, a print statement runs and tells the user how many of the elements are duplicates.