• C

# Statistical function Mode

Using a 1-D array to calculate the most frequent numbers in a file. I have a function called mode that returns the mode value. I had the array defined in Main() but don't know how to save group the numbers so I can increment the counter for each of the same group. (i.e., if we have a simple array such as 1., 2., 5., 3. 3., 2., 1., 7.5, 2. in this case our mode is 2 because it happend more often.

Mode(int n, list[count])
###### Who is Participating?

x
I wear a lot of hats...

"The solutions and answers provided on Experts Exchange have been extremely helpful to me over the last few years. I wear a lot of hats - Developer, Database Administrator, Help Desk, etc., so I know a lot of things but not a lot about one thing. Experts Exchange gives me answers from people who do know a lot about one thing, in a easy to use platform." -Todd S.

Commented:
Assume n is the number of elements in list[]

int Mode(int n, list[])
{
int i, j, mode, freq;

maxfreq = 1;
for (i=0; i < n; i++)
{
freq = 1;
for (j=i+1; j < n; j++)
{
if (list[i] == list[j])
freq++;
}
if (freq > maxfreq) {
maxfreq = freq ;
mode = list[i];
}
}
return mode;
}

0

Experts Exchange Solution brought to you by

Facing a tech roadblock? Get the help and guidance you need from experienced professionals who care. Ask your question anytime, anywhere, with no hassle.

Commented:
sorry, the line
int i, j, mode, freq;