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.
Reputation Points: 6442
Solved Threads: 1393
Bad Cop
Offline 11,807 posts
since Sep 2004