title: Find median from a sorted array using a function in c
body: <p>I have a program that takes integers from a array and prints out the largest, smallest, average and a sortes list. I need help with a function to find the median, and then print it out. Also my average only show whole numbers and no digits as I thought it would when I use float. But finding a median function is the important part.</p>
  
  <pre><code>#include &lt;stdio.h&gt;
  
  #define NUMBERS_SIZE 5
  
  int sum(int numbers[], int count)
  {
  
      int sum = 0;
  
      for (int i = 0; i &lt; count; i++)
          sum += numbers[i];
  
      return sum;
  }
  
  
  int maximum(int numbers[], int count)
  {
      int a;
  
  
      int max = numbers[0];
  
  
      for (a = 1; a &lt; count; a++)
          if (numbers[a] &gt; max)
              max = numbers[a];
  
      return max;
  }
  
  int minimum(int numbers[], int count)
  {
      int a;
  
  
      int min = numbers[0];
  
  
      for (a = 1; a &lt; count; a++)
          if (numbers[a] &lt; min)
              min = numbers[a];
  
      return min;
  }
  
  int average(int numbers[], int count)
  {
      float avg;
      int sum = 0;
  
      for (int i = 0; i &lt; count; i++)
          sum += numbers[i];
  
      avg = sum/count;
  
      return avg;
  }
  
  int cmpfunc (const void * a, const void * b) {
      return ( *(int*)a - *(int*)b );
  }
  
  
  
  
  int main()
  {
      int numbers[NUMBERS_SIZE];
  
      int n;
  
      float median=0;
  
      for (int i = 0; i &lt; NUMBERS_SIZE; i++)
      {
          printf("Enter integer: ");
          scanf("%i", &amp;numbers[i]);
      }
  
      int result3 = sum(numbers, sizeof(numbers) / sizeof(numbers[0]));
      printf("The sum is: %i\n", result3);
  
  
  
      int count3 = sizeof(numbers)/sizeof(numbers[0]);
      printf("Largest number entered is: %d\n", maximum(numbers, count3));
  
      int count1 = sizeof(numbers)/sizeof(numbers[0]);
      printf("Smallest number entered is: %d\n", minimum(numbers, count1));
  
      int count4 = sizeof(numbers)/sizeof(numbers[0]);
      printf("Average is %d\n", average(numbers, count4));
  
  
  
      qsort(numbers, NUMBERS_SIZE, sizeof(int), cmpfunc);
  
      printf("\nSorted: \n");
      for( n = 0 ; n &lt; NUMBERS_SIZE; n++ ) {
          printf("%d ", numbers[n]);
      }
  
  
      return 0;
  
  }
  </code></pre>