65.7k views
3 votes
Create a script that will find the Median value of {-100, 97, 83, 21, -50, 20, 101, 30} and {-100, 97, 83, 21, 20, 101, 30}.[THE USER SHOULD BE PROMPTED TO TYPE IN THE SIZE OF ARRAY. THEN, EACH FOLLOWING NUMBER THAT USER TYPES IN SHOULD BE STORED IN THIS ARRAY. Whole computation has to be done by accessing elements in the array.) Use C language and please require detailed PSEUDOCODEs.

User Castilho
by
7.8k points

1 Answer

7 votes

Final answer:

A script in C to find the median involves prompting for array size, filling the array with user input, sorting the array, then calculating the median depending on whether the number of elements is odd or even.

Step-by-step explanation:

Pseudocode for Finding the Median in an Array

Here is a step-by-step pseudocode for creating a script in C to find the median value of an array of integers:

Prompt the user for the size of the array.

Initialize an array of that size.

Use a for-loop to read values from the user to fill the array.

Sort the array in ascending order.

If the number of elements (n) is odd, the median is the middle element: median = array[(n-1)/2].

If n is even, the median is the average of the two middle elements: median = (array[n/2 - 1] + array[n/2]) / 2.

Output the median value.

To implement sorting, you can use a simple bubble sort or any efficient sorting algorithm like quicksort or mergesort. Remember to consider integer division when calculating the average of two integers in C

User Satyam Koyani
by
8.1k points