[填空题] 本程序的功能是查找一组数据中的众数。所谓众数,就是在这组数据中出现次数最多的数.注意:一组数据中的众数可能有多个.(即有多个数据的出现次数相同)。事件过程Cmdfind主要功能是生成n个随机整数存入数组,再调用Freq过程,求出数组中每个不相同的数据出现的次数:再求出其中最大的出现次数值,最后,将求出相应的众数输出。请完善本程序。Option ExplicitOption base 1Private Sub Cmdfind_Click()Dim a() As Integer,n As Integer,i As IntegerDim Shu() As Integer,Cs() As Integer,Max As Integern=InputBox("输入数据个数:","查找众数",20)ReDima(n)RandomizeFor i=1 To na(i)=Int(Rnd*5)+5Text1=Text1 &Str(a(i))If i Mod 10=0 Then Text1=Text1 &vbCrLfNext iCall Freq(a,Shu,Cs)Max=Cs(1)For i=2 To UBound(Cs)If Cs(i)>Max Then()End IfNext iFor i=1 To UBound(Cs)If () Then Text2=Text2 &Shu(i) & " "Next iEnd SubPrivate Sub Freq(a() As Integer,Shu() As Integer,Cs() As Integer)’shu数组用于存放A数组中不相同数据的值’Cs数组用于存放对应不相同数据出现的次数Dim i As Integer,j As Integer,js As Integer,n As IntegerFor i=1 To UBound(a)js=1For j=1 To n ’搜索数组a中不相同的数据If Shu(j)=a(i) Then Exit ForNext jIf ()
正确答案:max=cs(i);cs(i)=max;j>n;preserve shu(n),cs(n);js=js+A
欢迎分享,转载请注明来源:内存溢出
评论列表(0条)