
Patrick B. answered 03/24/21
Math and computer tutor/teacher
First you must change the Median method from
private to public
Then in Main():
Program myProgram = new Program();
MyProgram.Median(ages);
Karanbir S.
asked 03/24/21using 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] + " ");
}
}
}
Patrick B. answered 03/24/21
Math and computer tutor/teacher
First you must change the Median method from
private to public
Then in Main():
Program myProgram = new Program();
MyProgram.Median(ages);
Get a free answer to a quick problem.
Most questions answered within 4 hours.
Choose an expert and meet online. No packages or subscriptions, pay only for the time you need.