|
-
Apr 9th, 2007, 01:36 AM
#1
Thread Starter
Hyperactive Member
[RESOLVED] how to get the median?
hello!
how could you solve this?
given: 1,3,5,6
median = (3 + 5) / 2
any idea?
-
Apr 9th, 2007, 02:03 AM
#2
Re: how to get the median?
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.
-
Apr 9th, 2007, 02:13 AM
#3
Thread Starter
Hyperactive Member
Re: how to get the median?
pls. give me an example i am new c#...
you change ur pix huh!
-
Apr 9th, 2007, 02:58 AM
#4
Re: how to get the median?
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.
-
Apr 9th, 2007, 03:26 AM
#5
Thread Starter
Hyperactive Member
Re: how to get the median?
ok i understand...
but i can't figure out how could i get the indexes
imagine that i have 4 textboxes.
-
Apr 9th, 2007, 03:55 AM
#6
Re: how to get the median?
Put the values from the textboxes into an array, sort it, and then implement the algo J provided using the resulting array indices.
-
Apr 9th, 2007, 07:01 AM
#7
Thread Starter
Hyperactive Member
Re: how to get the median?
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];
-
Apr 9th, 2007, 08:37 AM
#8
Re: [RESOLVED] how to get the median?
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.
Posting Permissions
- You may not post new threads
- You may not post replies
- You may not post attachments
- You may not edit your posts
-
Forum Rules
|
Click Here to Expand Forum to Full Width
|