Well, do you understand what the frequency and mode are? The mode can be easily found once you've obtained the frequency, and the frequency is trivial with the standard library:
#include <cstddef>
#include <iostream>
#include <map>
#define length(x) (sizeof (x) / sizeof *(x))
int main()
{
int a[] = {1,5,4,5,8,9,5,1,4,7,8,5};
std::map<int, int> freq;
for ( size_t i = 0; i < length ( a ); i++ )
++freq[a[i]];
std::map<int, int>::const_iterator it = freq.begin();
while ( it != freq.end() ) {
std::cout<< it->first <<": "<< it->second <<std::endl;
++it;
}
}
Now it's just a matter of finding the item with the largest value for second.
Narue
Bad Cop
15,460 posts since Sep 2004
Reputation Points: 6,464
Solved Threads: 1,401