Solved

Statistical function Mode

Posted on 1998-02-12
3
195 Views
Last Modified: 2011-10-03
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
Comment
Question by:catalyst19002800
  • 2
3 Comments
 
LVL 3

Accepted Solution

by:
q2guo earned 100 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

by:q2guo
ID: 1257236
sorry, the line
int i, j, mode, freq;
should read
int i, j, mode, freq, maxfreq;
0
 

Author Comment

by:catalyst19002800
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

IT, Stop Being Called Into Every Meeting

Highfive is so simple that setting up every meeting room takes just minutes and every employee will be able to start or join a call from any room with ease. Never be called into a meeting just to get it started again. This is how video conferencing should work!

Join & Write a Comment

Suggested Solutions

An Outlet in Cocoa is a persistent reference to a GUI control; it connects a property (a variable) to a control.  For example, it is common to create an Outlet for the text field GUI control and change the text that appears in this field via that Ou…
This tutorial is posted by Aaron Wojnowski, administrator at SDKExpert.net.  To view more iPhone tutorials, visit www.sdkexpert.net. This is a very simple tutorial on finding the user's current location easily. In this tutorial, you will learn ho…
The goal of this video is to provide viewers with basic examples to understand opening and writing to files in the C programming language.
The goal of this video is to provide viewers with basic examples to understand opening and reading files in the C programming language.

743 members asked questions and received personalized solutions in the past 7 days.

Join the community of 500,000 technology professionals and ask your questions.

Join & Ask a Question

Need Help in Real-Time?

Connect with top rated Experts

14 Experts available now in Live!

Get 1:1 Help Now