Karanbir S.

asked • 03/24/21

Please help me plug in the median method into my code. I have the method in the public class program. it is static private.but don't know how to print/output. it in the main.

using System;

using System.Linq;

public class Program

{

static private float Median(float[] array)

{

float[] tempArray = array;

int count = tempArray.Length;

Array.Sort(tempArray);

float medianValue = 0;

if (count % 2 == 0)

{

float middleElement1 = tempArray[(count / 2) - 1];

float middleElement2 = tempArray[(count / 2)];

medianValue = (middleElement1 + middleElement2) / 2;

}

else

{

medianValue = tempArray[(count / 2)];

}


return medianValue;

}


public static void Main()

{

float[] ages = {36, 17, 15, 16, 15, 14, 15, 15,14, 15, 14, 14, 16, 19, 15, 18, 15, 17, 14, 14, 17, 15, 16, 16};

Console.WriteLine("There are " + ages.Length + " people in the class.");

Console.WriteLine("The ages of othe peole in Ms. Durning's 7th period class are: ");

for (int i = 0; i < ages.Length; i++)

{

Console.Write(ages[i]+" ");

}

Console.WriteLine("\n The average of the ages in the class is " + ages.Average());

float[] agesCopy = new float[ages.Length];

Array.Copy(ages, agesCopy, ages.Length);

Array.Sort(agesCopy);

Console.WriteLine("The ages of the people in Ms. Durning's 7th period class from smallest to largest are: ");

for (int i = 0; i < ages.Length; i++)

{

Console.Write(agesCopy[i] + " ");

}

}

}

1 Expert Answer

By:

Still looking for help? Get the right answer, fast.

Ask a question for free

Get a free answer to a quick problem.
Most questions answered within 4 hours.

OR

Find an Online Tutor Now

Choose an expert and meet online. No packages or subscriptions, pay only for the time you need.