若實(shí)現(xiàn)上述功能的程序如下,請(qǐng)?jiān)诩涌蛱幮薷暮线m代碼,使程序正常運(yùn)行. Private Sub Command1_Click ( ?。?br />Dim i As Integer,n As Integer,f As Integer Dim max As Integer'變量 max 表示出現(xiàn)最多的字母 Dim sum As Integer'sum 表示字母總數(shù) Dim zm(1To 26)As Integer'數(shù)組 zm 存放 26 個(gè)字母出現(xiàn)的次數(shù) Dim s As String,c As String Dim cx As String'變量 cx 存放次數(shù)最多的字符 s=Text1.Text For i=1To Len(s) c=Mid(s,i,1) If c>=“a“And c<=“z“Then n= zm(n)=zm(n)+1 sum=sum+1 End If Next i max=0 For j=1To 26 If zm(j)>max Then :cx=““ If zm(j)=max Then cx=cx+““+Chr(Asc(“a“)+j-1) End If Next j f=Int(max/sum*100) Label2.Caption=“字母:“& cx &“次數(shù):“& max &“頻率:“& Str(f) &“%“ End Sub.
17.小李編寫 VB 程序,功能如下:單擊“生成數(shù)組”按鈕 Command1,則隨機(jī)生成 13 個(gè)取值范圍是 1~13 的正整數(shù),分別存儲(chǔ)到數(shù)組 a 中,對(duì)數(shù)組 a 的元素進(jìn)行升序排列,并在標(biāo)簽label1 中顯示;再單擊“連續(xù)數(shù)”按鈕 Command2,則在排序后的數(shù)組 a 中查找連續(xù)個(gè)數(shù)最多(忽略重復(fù)數(shù)值)的一組數(shù)值(即:連續(xù)數(shù)),若有兩組連續(xù)數(shù)個(gè)數(shù)一樣多,則取數(shù)值小的一組,將連續(xù)數(shù)顯示在標(biāo)簽 label2 中.運(yùn)行界面如圖所示.
若實(shí)現(xiàn)上述功能的程序如下,請(qǐng)?jiān)趧澗€處填寫合適代碼,使程序正常運(yùn)行. Dim a(1To 13)As Integer Dim n As Integer Private Sub Command1_Click ( ?。?br />Dim i As Integer,s As String,j As String Randomize n=13 For i=1To n a(i)=Int(Rnd*13)+1 Next i For i=1To n-1 For j=i+1To n If a(j)<a(i) Then t=a(j): ①:a(i)=t End If Next j Next i s=““ For i=1To n s=s+Str(a(i)) If ② Then s=s+“,“ Next i Label1.Caption=s End Sub Private Sub Command2_Click ( ?。?br />Dim i As Integer,j As Integer Dim t As Integer,k As Integer Dim max As Integer'存儲(chǔ)連續(xù)數(shù)個(gè)數(shù)最大值 Dim begin As Integer'存儲(chǔ)連續(xù)數(shù)開始的數(shù)值 k=1 max=1 For i=2To 13 If a(i)=a(i-1)+1Or a(i)=a(i-1)Then If ③ Then k=k+1 If k>max Then max=k begin= ④ End If Else k=1 End If Next i s=““ For j=begin To begin+max-1 s=s+Str(j) Next j Label2.Caption=s End Sub.