C Exercises: Find the median of two sorted arrays of same size
64. Median of Two Sorted Arrays (Same Size)
Write a program in C to find the median of two sorted arrays of the same size.
Expected Output :
The given array - 1 is : 1 5 13 24 35
The given array - 2 is : 3 8 15 17 32
The Median of the 2 sorted arrays is: 14
The task is to write a C program that finds the median of two sorted arrays of the same size. The program should merge the two arrays while maintaining the sorted order and then determine the median value of the combined array. The median is the middle element when the total number of elements is odd, or the average of the two middle elements when it is even.
Sample Solution:
C Code:
Output:
The given array - 1 is : 1 5 13 24 35 The given array - 2 is : 3 8 15 17 32 The Median of the 2 sorted arrays is: 14
For more Practice: Solve these Related Problems:
- Write a C program to find the median of two sorted arrays of equal size using a binary search approach.
- Write a C program to merge two sorted arrays of the same size and then compute the median without fully sorting the merged array.
- Write a C program to find the median of two sorted arrays using recursion and divide-and-conquer techniques.
- Write a C program to determine the median by comparing the medians of the two arrays and then narrowing the search range.
C Programming Code Editor:
Previous: Write a program in C to replace every element with the greatest element on its right side.
Next: Write a program in C to find the product of an array such that product is equal to the product of all the elements of arr[] except arr[i].
What is the difficulty level of this exercise?
Test your Programming skills with w3resource's quiz.