vb.net求众数,编程求众数
VB.net中如何求出2维数组,每个维度上的值得个数
每行的数字个数不同,你说的这是不规则数组,解决方案如下:
10年积累的成都网站建设、网站设计经验,可以快速应对客户对网站的新想法和需求。提供各种问题对应的解决方案。让选择我们的客户得到更好、更有力的网络服务。我虽然不认识你,你也不认识我。但先做网站设计后付款的网站建设流程,更有新兴免费网站建设让你可以放心的选择与我们合作。
Dim b As String = ""
Dim a As Integer()() = New Integer(9)() {}
a(0) = New Integer() {0, 1, 2, 3, 4, 5, 6, 7, 8, 9}
a(1) = New Integer() {0, 3, 4, 5}
a(2) = New Integer() {0, 4, 5, 6, 7}
a(3) = New Integer() {0, 6, 5, 8, 9, 1}
a(4) = New Integer() {0, 2, 5, 1, 7}
a(5) = New Integer() {0, 4, 2, 6, 7, 3}
a(6) = New Integer() {0, 4, 5, 3, 2}
a(7) = New Integer() {0, 4, 1, 6, 2, 8, 5, 3}
a(8) = New Integer() {0, 4, 9, 6, 3, 5, 7}
a(9) = New Integer() {0, 1, 5, 9, 7, 6, 2, 4, 3, 8}
For i As Integer = 0 To a.GetUpperBound(0)
b = "第" i + 1 "行有" a(i).GetUpperBound(0) + 1 "个数" vbCrLf
Next
MessageBox.Show(b)
用vb.net求三个数中的最大值以及最小值函数的编写
MaxOrMin 指示返回最大还是最小.
Private Function Math(ByVal num1 As Integer, ByVal num2 As Integer, ByVal num3 As Integer, ByVal MaxOrMin As Short) As Integer
Dim s() As Integer = {num1, num2, num3}
Dim max, min As Integer
If s(0) s(1) Then
min = s(0)
max = s(1)
End If
If s(1) s(2) Then
min = s(1)
max = s(2)
End If
If MaxOrMin = 0 Then Return max
If MaxOrMin = 1 Then Return min
End Function
VB求众数
Option Explicit
Private Sub Form_Load() '所有的数据以空格间隔输入在text中,注意最后一个数字输入好后还要输入空格的
Text1 = "11 22 1 3 3 4 5 6 5 44 3 2 3 4 5 6 7 8 6 5 4 3 2 2 1 1 1 1 2 3 4 4 5 5 6 6 7"
Text1 = Text1 "4 5 6 7 8 9 9 9 9 9 8 7 6 5 5 4 3 3 3 "
End Sub
Private Sub Command1_Click()
Dim A, i As Integer, flag As Boolean
Dim Temp() As String, N() As Integer, j As Integer, k As Integer
Dim max As Integer, B() As Integer '这里是用来求众数的,也就是出现最多次数的,因为众数可以不为一个,我这里就用数组表示了
A = Split(Text1, " ")
ReDim Temp(1)
ReDim N(1)
Temp(1) = A(0)
j = 1
For i = 0 To UBound(A) - 1
For k = 1 To j
If A(i) = Temp(k) Then
N(k) = N(k) + 1
flag = True
Exit For
End If
Next
If flag Then
flag = False
Else
j = j + 1
ReDim Preserve Temp(j)
ReDim Preserve N(j)
Temp(j) = A(i)
N(j) = 1
End If
Next
For i = 1 To j '这个循环可以显示出所有数出现的次数,可以用来检验
Print Temp(i) "出现了" N(i) "次"
Next
ReDim B(1) '这个循环是为了求出出现最多的数,因为有多个众数所以用这个方法了
max = N(1)
k = 1
B(1) = 1
For i = 1 To j
If max N(i) Then
max = N(i)
ReDim B(1)
B(1) = i
k = 1
ElseIf max = N(i) Then
k = k + 1
ReDim Preserve B(k)
B(k) = i
End If
Next
Print "众数是:"
For i = 1 To k
Print Temp(B(i))
Next
End Sub
网站题目:vb.net求众数,编程求众数
本文路径:http://pwwzsj.com/article/dscsjig.html