i want make modal value calculator, calculates modal value , repetition
the idea make list of data , repetition shown in graph.
this code start with:
public class dim a1(100), a2(100), rep(100), repmer(100), amer(100) single, n, count, m single, z, k, c, mars integer n = inputbox("how many data?", "reptest") count = 0 count = 0 n - 1 a1(count) = inputbox("add value", "reptest") next z = n run = 0 n - 1 mars = c z = z - 1 k = 0 moon = 0 (n - 1) if a1(z) = a1(moon) k = k + 1 a2(run) = a1(z) rep(run) = rep(run) + k if rep(run) > 2 rep(run) = rep(run) - 1 end if end if next msgbox(a2(run)), , "modal value") msgbox(rep(run)),, "repetition") next end class
however, if make massage box outside main 2nd loop, have make loop same value 0 (n-1), match data position in array.
what want me please is:
i have save modal value , repetition of 1 value in same position in array, because if use code output of n = 5 , enter value 2 ,2 ,2 ,1,1. output 5 massage box 3 equal value 2, , 2 equal value 1.
you can test copy code , insert form in vb.net.
with pictures:
see link: picture describe result
you can see output more 1 each value, how can store value , repetition in 1 position in array?
thank reading, please want code answer. :)
update
if want count duplicates(repetitions) of values , use needs:
- create custom class can keep information value , amount of repetitions
public class repetitionvalue public property value single public property repetitionamount int32 public sub new(value single) me.value = value me.repetitionamount = 1 end sub end class
- collect values , count duplicates, save in
directory
collection
directory easy object value - use collection manipulating data
public sub yoursybname() dim values new list(of single)() dim numberofdata int32 numberofdata = int32.parse(inputbox("how many data?", "reptest")) count int32 = 0 numberofdata - 1 values.add(inputbox("add value", "reptest")) next dim modals new dictionary(of single, repetitionvalue)() each value single in values if modals.containskey(value) = true modals(value).repetitionamount += 1 else modals.add(new repetitionamount(value)) end if next 'use collection needs 'for example if have 5 data, enter 1 . 5 . 1 . 2 . 1. 'then want divide repetition of value 1 repetition of value 5. dim valueof1 repetitionvalue = modals(1) dim valueof5 repetiotionvalue = modals(5) dim divideresult decimal = valueof1.repetitionamount/valueof5.repetitionamount end public
Comments
Post a Comment