Go4Expert

Go4Expert (http://www.go4expert.com/)
-   C (http://www.go4expert.com/forums/c/)
-   -   Finding mode and median values (http://www.go4expert.com/forums/finding-mode-median-values-t3991/)

gavin_55 23Apr2007 04:59

Finding mode and median values
 
I apologise if im posting this in the wrong area.
I'm using Visual Studio and trying to write a small program that takes an array, sorts it in ascending order and then calculates average, mode and median of those values.
So far i have sorted it using selective sort, calculated the average but am struggling with the mode and median.
This is what i have for my median function so far. I beleive the theory should work behind it.

Code:

double getMedian(int num[], int length )
{
        double value;
        int position = 0;
        value = 0;
        if (length % 2 != 0)
        {
                position = (length / 2);
                value = num[position];
        }
        else
        {
                position = (length / 2);
                value = (num[position]+num[position-1])/2;
        }
        return value;
}


DaWei 24Apr2007 17:55

Re: Finding mode and median values
 
So what is it DOING that you don't like? Are we to guess? Someone might; I will not. Also, learn how to put code tags around your own code. Poor Shabbir must be wearing his mouse out.

shabbir 24Apr2007 18:10

Re: Finding mode and median values
 
Quote:

Originally Posted by DaWei
Poor Shabbir must be wearing his mouse out.

Till everyone on this planet does not know how to put code inside the code tag.

Moderation is a difficult job. :cool:


All times are GMT +5.5. The time now is 10:18.