[填空題] 本程序的功能是查找一組數(shù)據(jù)中的眾數(shù)。所謂眾數(shù),就是在這組數(shù)據(jù)中出現(xiàn)次數(shù)最多的數(shù).注意:一組數(shù)據(jù)中的眾數(shù)可能有多個(gè).(即有多個(gè)數(shù)據(jù)的出現(xiàn)次數(shù)相同)。事
[填空題] 本程序的功能是查找一組數(shù)據(jù)中的眾數(shù)。所謂眾數(shù),就是在這組數(shù)據(jù)中出現(xiàn)次數(shù)最多的數(shù).注意:一組數(shù)據(jù)中的眾數(shù)可能有多個(gè).(即有多個(gè)數(shù)據(jù)的出現(xiàn)次數(shù)相同)。事件過程Cmdfind主要功能是生成n個(gè)隨機(jī)整數(shù)存入數(shù)組,再調(diào)用Freq過程,求出數(shù)組中每個(gè)不相同的數(shù)據(jù)出現(xiàn)的次數(shù):再求出其中最大的出現(xiàn)次數(shù)值,最后,將求出相應(yīng)的眾數(shù)輸出。請(qǐng)完善本程序。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("輸入數(shù)據(jù)個(gè)數(shù):","查找眾數(shù)",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數(shù)組用于存放A數(shù)組中不相同數(shù)據(jù)的值’Cs數(shù)組用于存放對(duì)應(yīng)不相同數(shù)據(jù)出現(xiàn)的次數(shù)Dim i As Integer,j As Integer,js As Integer,n As IntegerFor i=1 To UBound(a)js=1For j=1 To n ’搜索數(shù)組a中不相同的數(shù)據(jù)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
詞條內(nèi)容僅供參考,如果您需要解決具體問題
(尤其在法律、醫(yī)學(xué)等領(lǐng)域),建議您咨詢相關(guān)領(lǐng)域?qū)I(yè)人士。