Computer Science Canada Finding the mode and median if the given numbers |
Author: | MysticVegeta [ Wed Nov 17, 2004 5:42 pm ] |
Post subject: | Finding the mode and median if the given numbers |
I have 10 input numbers, now i know how to calculate the mean and maximum and minimum but i am stuck with how to calculate the mode |
Author: | Neo [ Wed Nov 17, 2004 6:25 pm ] | ||
Post subject: | |||
Well, I dont know if there is an easier way but this is how I would do it...
|
Author: | Andy [ Wed Nov 17, 2004 6:26 pm ] |
Post subject: | |
have two variables one maned maximum, one namedm minimum and set the minimum to maxint and maximum not minint run a for loop through the list of numbers, and check if the number is larger than maximum or smaller than minimum, then set that number to the maximum/minimum.. after the whole list, u'd have the max and min |
Author: | zylum [ Wed Nov 17, 2004 10:20 pm ] | ||
Post subject: | |||
he knows how to do that, hes asking how to find the mode ![]()
|
Author: | MysticVegeta [ Thu Nov 18, 2004 8:34 pm ] |
Post subject: | |
Uh thanks ppl but can some1 help me with median????????????????? |
Author: | zylum [ Thu Nov 18, 2004 8:53 pm ] |
Post subject: | |
common, just sort the array and get the middle element ![]() |
Author: | MysticVegeta [ Fri Nov 26, 2004 7:35 am ] |
Post subject: | |
I tried to sort the array but somehow it doesnt work, the highest number goes in the last or in the middle, can you post an example? |
Author: | Blade [ Fri Nov 26, 2004 11:00 am ] |
Post subject: | |
basically to sort an array, you will need 2 for loops... one from 1 to your max(call it "i") .. and one from "i" to your max (call it "j")... because this type of sorting is so unefficient, you can make it more efficient by running the second loop this way, because you will have either the smallest or the largest number at the beginning of the array by the time you run through "i" once, so you can cut out comparing that value in future runs.. now if you are going to sort it from smallest to largest, you're going to have to compare it to see if number(i) is greater than number(j) .. if it is, you will then switch them.. obviously you will have to have a temporary variable to store one of the numbers temp:=number(i)... then you will set the other number to the one you have a backup of number(i):=number(j) ... then you can set the first number to the other number(j):=temp ... not too complicated eh? now you can get your median by dividing maxnum by 2 and getting the value of that element btw, this is the most unefficent sort method there is, but its also the simplest, i'm not gonna get into the other types |
Author: | MysticVegeta [ Sat Nov 27, 2004 5:20 pm ] |
Post subject: | |
Any examples???? Pls |
Author: | Blade [ Sun Nov 28, 2004 5:21 am ] | ||
Post subject: | |||
i dont know how it can be any clearer than that without giving you the answer :S
|
Author: | MysticVegeta [ Tue Nov 30, 2004 5:33 pm ] |
Post subject: | |
Error at max |
Author: | zylum [ Tue Nov 30, 2004 5:55 pm ] |
Post subject: | |
you're not even trying are you ![]() |
Author: | MysticVegeta [ Sun Dec 19, 2004 6:59 pm ] | ||
Post subject: | |||
yep gotcha
|