Answered step by step
Verified Expert Solution
Link Copied!

Question

1 Approved Answer

In this problem, you will write a program that computes the median of a set of numbers ( median 1 . cc ) . The

In this problem, you will write a program that computes the median of a set of numbers
(median1.cc). The median of a list of number is computed by first sorting the list in
ascending order, and choosing the number in the middle. If there is an even number
of numbers, the median is the average of the two numbers in the middle.
For example, the median of the list
1,3,50,75,80
is 50, while the median of the list
1,3,50,75,80,100
is 62.5.
(a) Write the function:
void sort(int *A, int n);
which sorts the array A of n elements in ascending order. You may use any sorting
algorithm you learned from CPSC 1620.
(b) Write the function:
double median(int *A, int n);
which computes the median of the array A of n elements. It is acceptable if the
function rearranges the elements of A.
(c) Write the main program which asks the user to enter n, allocates an array of n
elements, and displays the median. The program should repeat as long as n >=1.
When n <1, exit the program. Be sure that there is no memory leak.
1
Sample session:
Enter the size of the list (<1 to quit): 6
Enter element 1: 100
Enter element 2: 50
Enter element 3: 75
Enter element 4: 1
Enter element 5: 80
Enter element 6: 3
The median is 62.5.
Enter the size of the list (<1 to quit): 0

Step by Step Solution

There are 3 Steps involved in it

Step: 1

blur-text-image

Get Instant Access to Expert-Tailored Solutions

See step-by-step solutions with expert insights and AI powered tools for academic success

Step: 2

blur-text-image

Step: 3

blur-text-image

Ace Your Homework with AI

Get the answers you need in no time with our AI-driven, step-by-step assistance

Get Started

Recommended Textbook for

SQL Server T-SQL Recipes

Authors: David Dye, Jason Brimhall

4th Edition

1484200616, 9781484200612

More Books

Students also viewed these Databases questions

Question

=+23. Advertising strategies EVPI.

Answered: 1 week ago