vb为什么说我下标越界。题目见文章
题目是把20个数导入一个数组,求其中频率最高的数,还有出现的次数。比如把1,5,4,3,5,8,5存放到数组a,出现频率最高的是5,出现次数是3.求大神解答!!!!!!!...
题目是把20个数导入一个数组,求其中频率最高的数,还有出现的次数。比如把1,5,4,3,5,8,5存放到数组a,出现频率最高的是5,出现次数是3.
求大神解答!!!!!!!!!!
Option Base 1
Private Sub Form_Load()
Dim a(1 To 20) As Integer, b() As Integer, fmax As Integer
For i = 1 To 20
a(i) = CInt(InputBox("请输入第" & i & "个数"))
Next i
For i = 1 To 20
Print a(i);
Next i
For i = 1 To 20
b(i) = 0
fmax = 0
For j = 1 To i
If a(i) = a(j) Then b(i) = a(i)
If b(i) > fmax Then fmax = b(i)
Next j
Next i
Print
Print Tab(2); "出现频率最高的数值是:";
For i = 1 To 20
If b(i) = fmax Then Print a(i)
Next i
Print
Print Tab(2); "出现的次数是:"; fmax
End Sub 展开
求大神解答!!!!!!!!!!
Option Base 1
Private Sub Form_Load()
Dim a(1 To 20) As Integer, b() As Integer, fmax As Integer
For i = 1 To 20
a(i) = CInt(InputBox("请输入第" & i & "个数"))
Next i
For i = 1 To 20
Print a(i);
Next i
For i = 1 To 20
b(i) = 0
fmax = 0
For j = 1 To i
If a(i) = a(j) Then b(i) = a(i)
If b(i) > fmax Then fmax = b(i)
Next j
Next i
Print Tab(2); "出现频率最高的数值是:";
For i = 1 To 20
If b(i) = fmax Then Print a(i)
Next i
Print Tab(2); "出现的次数是:"; fmax
End Sub 展开
1个回答
展开全部
修改后的程序如下:
Option Base 1
Private Sub Command1_Click()
Dim a(1 To 20) As Integer, b(0 To 20) As Integer, fmax As Integer
For i = 1 To 20
a(i) = Int(Rnd * 10)
Next i
For i = 1 To 20
Print a(i);
b(a(i)) = b(a(i)) + 1
Next i
fmax = 1
For i = 1 To 20
If b(i) > b(fmax) Then fmax = i
Next i
Print Tab(2); "出现频率最高的数值是:"; fmax
For i = 1 To 20
If a(i) = fmax Then Print "No."; i
Next i
Print Tab(2); "出现的次数是:"; b(fmax)
End Sub
追问
太感谢了!能不能再帮我看看别的题?#_#
本回答被提问者和网友采纳
已赞过
已踩过<
评论
收起
你对这个回答的评价是?
推荐律师服务:
若未解决您的问题,请您详细描述您的问题,通过百度律临进行免费专业咨询