I'm trying to write code for finding the number of same number in
array.
For example, in [1, 2, 3, 3, 4], the number of same number is 2.
In [1, 2, 1, 3, 1], the number of same number is 3.
How can I implement this?
Please, help me.
I'm trying to write code for finding the number of same number in
array.
For example, in [1, 2, 3, 3, 4], the number of same number is 2.
In [1, 2, 1, 3, 1], the number of same number is 3.
How can I implement this?
Please, help me.
Do a bin sort/count on it.
for(i = 0; i < NumOFelements; i++)
binArray[arrayName[i]]++;
Now print it out. You know how many there are of each number. Now get the highest number. And how will you know what number that is?
HighestNumber will equal bin[HighestNumber]
Oy! ;)
Let me give you a pseudo code for this program.
1. Read the numbers in an array and initialize an array as 'count' of same size.
2. Use a for loop which goes through each element one by one.
3. Within the for loop compare the selected element of array with each element of the array by using second for loop and if the elements matches, the corresponding count gets incremented.
4. When the count is done for all the elements you can find the maximum value of count and you print that out.
This procedure might be long but its an easy way to understand it.