• C

implementing a function

Implement the function find_median. The function find_median accepts three integer values as formal parameters and returns the median of the three numbers. The median of three numbers is the number that is greater than one of the numbers and less than the other number. The median of 10, 30 and 20 is 20. The median of 5, 5 and 5 is 5. The median of 12, 20 and 12 is 12. A call to find_median will take the form:
     median = find_median(num1,num2,num3);

i need this written out to implement this function...thanks in advance!
Who is Participating?

Improve company productivity with a Business Account.Sign Up

imladrisConnect With a Mentor Commented:
Do it by sorting the values:

int find_median(int num1,int num2,int num3)
{    int tmp;

     {    tmp=num1;   /* swap num1 and 2*/
     /* Now if num3 is <= num1
        the median is num1 */

     /* if not returned, num3 > num1
        if it is also <= num2
        then num3 is the median  */

     /* if not returned, num3 > num2
        as well so ....  */

hmmm , beat to me,imladris :)
However , here it is:
int find_median(num1,num2,num3)
   int seri[3],temp;
   for(int i=0;i<2;i++){
   return seri[0]>seri[1]?seri[0]:seri[1];

Question has a verified solution.

Are you are experiencing a similar issue? Get a personalized answer when you ask a related question.

Have a better answer? Share it in a comment.

All Courses

From novice to tech pro — start learning today.