Want to win a PS4? Go Premium and enter to win our High-Tech Treats giveaway. Enter to Win

x
Solved

# Statistical function Mode

Posted on 1998-02-12
Medium Priority
237 Views
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])
0
Question by:catalyst19002800
[X]
###### Welcome to Experts Exchange

Add your voice to the tech community where 5M+ people just like you are talking about what matters.

• Help others & share knowledge
• Earn cash & points
• 2

LVL 3

Accepted Solution

q2guo earned 400 total points
ID: 1257235
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

LVL 3

Expert Comment

ID: 1257236
sorry, the line
int i, j, mode, freq;
int i, j, mode, freq, maxfreq;
0

Author Comment

ID: 1257237
I really know this will work. Even though I am a novice. But this response from my encrypted desciption is amazing. Thank so much q2gue. (Excellent!! I may aks another question)
0

## Featured Post

Question has a verified solution.

If you are experiencing a similar issue, please ask a related question

Preface I don't like visual development tools that are supposed to write a program for me. Even if it is Xcode and I can use Interface Builder. Yes, it is a perfect tool and has helped me a lot, mainly, in the beginning, when my programs were small…
Summary: This tutorial covers some basics of pointer, pointer arithmetic and function pointer. What is a pointer: A pointer is a variable which holds an address. This address might be address of another variable/address of devices/address of fu…
The goal of this video is to provide viewers with basic examples to understand recursion in the C programming language.
The goal of this video is to provide viewers with basic examples to understand and use switch statements in the C programming language.
###### Suggested Courses
Course of the Month10 days, 3 hours left to enroll