Finding mode and median values

Discussion in 'C' started by gavin_55, Apr 23, 2007.

  1. gavin_55

    gavin_55 New Member

    Joined:
    Apr 23, 2007
    Messages:
    3
    Likes Received:
    0
    Trophy Points:
    0
    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;
    }
     
    Last edited by a moderator: Apr 23, 2007
  2. DaWei

    DaWei New Member

    Joined:
    Dec 6, 2006
    Messages:
    835
    Likes Received:
    5
    Trophy Points:
    0
    Occupation:
    Semi-retired EE
    Location:
    Texan now in Central NY
    Home Page:
    http://www.daweidesigns.com
    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.
     
  3. shabbir

    shabbir Administrator Staff Member

    Joined:
    Jul 12, 2004
    Messages:
    15,375
    Likes Received:
    388
    Trophy Points:
    83
    Till everyone on this planet does not know how to put code inside the code tag.

    Moderation is a difficult job. :cool:
     

Share This Page

  1. This site uses cookies to help personalise content, tailor your experience and to keep you logged in if you register.
    By continuing to use this site, you are consenting to our use of cookies.
    Dismiss Notice