# need hint how to filter the results

• 01-29-2005
kocika73
need hint how to filter the results
OK, I have an array with numbers, and an array with the number of occurences of each corresponding number from the number array. I need to display the numbers from number array which occured the most. The way I did it, it displays them and they repeat themselves. E.g. 7 occured 7 times, 87 occured 7 times, 7 occured 7 times etc. It is supposed to display it only once. Can somebody give me hint how to do that?
What I have so far is this:
Code:

```for(i = 0; i < SIZE; i++)     {       search = numbers[i];             for(j = 0; j < SIZE; j++)           {           if(numbers[j] == search)             occurences[i]++;           }     }   printf("\n");   largest_occ = occurences[0];   for(i = 0; i < SIZE; i++)       {         if(largest_occ < occurences[i])           largest_occ = occurences[i];       }   for(i = 0; i < SIZE; i++)       {         if(largest_occ == occurences[i])           {           modes[j] = largest_occ;           j++;           }       }```
The last for loop was to put all the modes in a separate array so I could filter it, but it does not work.
Any hints how I could go about it?
• 01-29-2005
Kleid-0
Code:

```  for(i = 0; i < SIZE; i++)     {       search = numbers[i];             for(j = 0; j < SIZE; j++)           {           if(numbers[j] == search)             occurences[i]++;           }     }     // What do you think j equals right now?   printf("\n");   largest_occ = occurences[0];   for(i = 0; i < SIZE; i++)       {         if(largest_occ < occurences[i])           largest_occ = occurences[i];       }   for(i = 0; i < SIZE; i++)       {         if(largest_occ == occurences[i])           {           // Do you think you're using j correctly?           modes[j] = largest_occ;           j++;           }       }```
• 01-29-2005
kocika73
Yes, I have already corrected the j problem, I know... However, it still did not solve the question how to filter the results...
• 01-29-2005
Kleid-0
Could you post your updated code that fixed the j variable issue?
• 01-29-2005
kocika73
I just reset it to "0" before the loop, it is only a counter... it's incremented right after the statement that uses it.
Code:

```for(i = 0; i < SIZE; i++)     {       search = numbers[i];             for(j = 0; j < SIZE; j++)           {           if(numbers[j] == search)             occurences[i]++;           }     }   printf("\n");   largest_occ = occurences[0];   for(i = 0; i < SIZE; i++)       {         if(largest_occ < occurences[i])           largest_occ = occurences[i];       }   j = 0;   for(i = 0; i < SIZE; i++)       {         if(largest_occ == occurences[i])           {           modes[j] = largest_occ;           j++;           }       }```
What I think is that the problem lies in what I put in the modes array...