Academic Integrity: tutoring, explanations, and feedback — we don’t complete graded work or submit on a student’s behalf.

Can you guys help me ? This is c++ In statistics, when a set of values is sorted

ID: 3765423 • Letter: C

Question

Can you guys help me ? This is c++

In statistics, when a set of values is sorted in ascending or descending order, its median

is the middle value. If the set contains an even number of values, the median is the

mean, or average, of the two middle values. Write a function that accepts as arguments

the following:

A) An array of integers

B) An integer that indicates the number of elements in the array

The function should determine the median of the array. This value should be returned

as a double . (Assume the values in the array are already sorted.)

   TEST DATA (1): 2                      = 2
   TEST DATA (2): 2 1                  = 1.5
   TEST DATA (5): 2 1 11 4 9        = 4
   TEST DATA (6): 2 1 11 4 9 34    = 6.5

Enter an integer to search for: Demonstrate your pointer prowess by using pointer
notation instead of array notation in this function.

Explanation / Answer

#include<iostream.h>
#include<conio.h>
double median(double a[], int n)
{
   int m;
   double r;
   if(n%2==0)
   {
       m=n/2;
       r=(a[m-1]+a[m])/2;
   }
   else
   {
       m=n/2;
       r=a[m];
   }
   return r;
}

void main()
{
   double a[]={1.2,2.5,3.6,4.7,5.4};
   double m;
   int i;

   m=median(a,5);

   cout<<"Median is "<<m;
   getch();
}              

Hire Me For All Your Tutoring Needs
Integrity-first tutoring: clear explanations, guidance, and feedback.
Drop an Email at
drjack9650@gmail.com
Chat Now And Get Quote