VOOZH about

URL: https://www.geeksforgeeks.org/c/find-median-of-numbers-in-an-array-in-c/

⇱ How to Find Median of Numbers in an Array in C? - GeeksforGeeks


  • Courses
  • Tutorials
  • Interview Prep

How to Find Median of Numbers in an Array in C?

Last Updated : 23 Jul, 2025

For an odd number of elements in an array, the median is the middle element, and for an even number, it’s the average of the two middle elements. In this article, we will learn how to find median of numbers in an array in C.

The median of an array can be determined is by first sorting the array and then finding the middle element or the average of two middle elements depending on the total number of elements. Let's look at an example:


Output
22.50

Explanation: The array is first sorted in ascending order using qsort() function with comparator comp(). As the number of elements was odd, the middle element is returned as median.

Using Quick Select Algorithm

Quick Select Algorithm is a variation of quick sort algorithm that tries to find the middle element by arranging the array using the quicksort's partition algorithm and removing the part of array from the consideration in each iteration.


Output
3
Comment
Article Tags: