![]() |
In C++, the array is a collection of elements of the same type, In this article, we will learn how to find the median of the array in C++. The median of the array will be the middle element if the number of elements is odd or the average of two middle elements if the number of elements is even in the sorted array. Example: Input: Finding Median of Array in C++To find the median of an element, we will first sort the elements of the array in ascending order using std::sort() function.
C++ Program to Find the Median of ArrayC++
Output
Median of the array is: 4 Time Complexity : O(nlogn), where n is the number of elements in the array. |
Reffered: https://www.geeksforgeeks.org
C++ |
Type: | Geek |
Category: | Coding |
Sub Category: | Tutorial |
Uploaded by: | Admin |
Views: | 15 |