0

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.

3
Contributors
2
Replies
3
Views
7 Years
Discussion Span
Last Post by Software guy
0

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! ;)

Edited by Adak: n/a

0

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.

This topic has been dead for over six months. Start a new discussion instead.
Have something to contribute to this discussion? Please be thoughtful, detailed and courteous, and be sure to adhere to our posting rules.