If i had five numbers say 40, 30, 40, 50, 40
how could I find the mode using an array ???
finding the mode
Moderators:Administrator, Global Moderator
Re: finding the mode
What do you mean by "mode"?
Re: finding the mode
incase you didn't go to school you should know that it means the most frequently occurint number in a list :P
Re: finding the mode
Heh-heh . . . your teachers must be proud.incase you didn't go to school you should know that it means the most frequently occurint number in a list :P
Anyway, here's a code that works:
-----------------------------------------------------
CLS
DEFINT A-Z
n = 5' How many numbers you have.
n = n - 1
DIM a(n, 1)
FOR x = 0 TO n
READ a(x, 0)
NEXT x
FOR x = 0 TO n
FOR y = 0 TO n
IF x <> y THEN
IF a(x, 0) = a(y, 0) THEN a(x, 1) = a(x, 1) + 1
END IF
NEXT y
NEXT x
FOR x = 1 TO n
IF a(x, 1) > a(x - 1, 1) THEN t = a(x, 0) ELSE t = a(x - 1, 0)
NEXT x
PRINT USING "Mode: ####"; t
END
DATA 40,30,40,50,40
-----------------------------------------------------
Try this, Artie
Edit: Neatened up code a bit.