Computer Science Canada Help with arrays!! ASAP! |
Author: | chibitenshi_03 [ Thu Mar 04, 2004 6:10 pm ] |
Post subject: | Help with arrays!! ASAP! |
i need to make a program using arrays that randomly output numbers. Then i need to calculate the average, median and mode. I know how to get the average but how do you find the median and mode? This is what i have so far: var count, sum : int sum := 0 % ask the user how many numbers there are put "How many numbers do you want to generate?" get count var number : array 1 .. count of int for a : 1 .. count randint (number (a), 1, 10)% randomly choose numbers put number (a), " " .. % output numbers sum := sum + number (a) % add up all the numbers end for put skip put "The average is ", sum / count, "." |
Author: | Cervantes [ Thu Mar 04, 2004 6:29 pm ] | ||
Post subject: | |||
to find the median you need to sort the numbers into another array. Ways to sort are many and found all across compsci.ca. Here is a bubble sort
once sorted, you output the middle element of the array. |
Author: | chibitenshi_03 [ Thu Mar 04, 2004 6:39 pm ] |
Post subject: | |
Do you kno how to do the mode? |
Author: | Cervantes [ Thu Mar 04, 2004 6:43 pm ] | ||
Post subject: | |||
been fiddling around with that one. It's kinda tricky. Here's what I've done. It's the basis. However you need to expand it to make it so that you can enter the number of random nums to be created. When you do that, however, you will also need to error proof it, as you will have problems with "array subscript is out of range".
from there you sort the mode array and output the biggest one. |
Author: | chibitenshi_03 [ Thu Mar 04, 2004 6:45 pm ] |
Post subject: | |
Thanks for the help! ^^ |