hello!
how could you solve this?
given: 1,3,5,6
median = (3 + 5) / 2
any idea?
Printable View
hello!
how could you solve this?
given: 1,3,5,6
median = (3 + 5) / 2
any idea?
1. Get the number of values.
2. Divide that number by 2.
3. If the result of step 2 is a whole number then get the value at that index.
4. If the result of step 2 is not a whole number then get the floor and ceiling of that number, get the two values at those indexes and average them.
See the Math.Floor and Math.Ceiling functions.
pls. give me an example i am new c#...
you change ur pix huh!
That's not C#. It's mathematics. Not only that, I'm guessing that this is homework, or at least a learning exercise. You've got the algorithm so give it a go. If you run into issues we can help, but you should try it yourself first.
ok i understand...
but i can't figure out how could i get the indexes
imagine that i have 4 textboxes.
Put the values from the textboxes into an array, sort it, and then implement the algo J provided using the resulting array indices.
sorry for bothering here is the answer...
int[] intArray = new int[] { Convert.ToInt16(txtEB1.Text), Convert.ToInt16(txtEB2.Text), Convert.ToInt16(txtEB3.Text) };
Array.Sort(intArray);
intMin = intArray[0];
intMedian = intArray[1];
intMax = intArray[2];
That's not the answer to the question you originally asked because that array only has three elements. You should write code that will work for any number of elements in the array, which you can do by following the algorithm that I provided.