實(shí)現(xiàn)上述功能的VB代碼如下,但加框處代碼有錯(cuò),請(qǐng)改正. Const n As Integer=10 Dim a(1To n) As Integer Private Sub Form_Load ( ?。?br />Dim i As Integer Randomize For i=1To n a(i)=Int(Rnd*100) List1.AddItem Str(a(i)) Next End Sub Private Sub Command1_Click ( ?。?br />Dim tmp As Integer,i As Integer,j As Integer,k As Integer For i=1To n-1 k=0 For j=n To i+1Step-1 If a(j)>a(j-1)Then
k=k+1 End If Next j If Then i=n Next i For i=1To n List2.AddItem Str(a(i)) Next i End Sub End Sub.
③移動(dòng)數(shù)組元素到新的位置:如果在已經(jīng)產(chǎn)生的號(hào)碼中找到比新號(hào)碼大的數(shù),從上一個(gè)產(chǎn)生的號(hào)碼開(kāi)始,到新號(hào)碼應(yīng)存放的數(shù)組元素,依次把他們向后面移動(dòng).以②中產(chǎn)生150為例,從a(4)開(kāi)始,讓a(5)的值等于a(4),a(4)的值等于a(3),依此類推,直到新號(hào)碼應(yīng)存放的數(shù)組元素a(2)為止. ④將新產(chǎn)生的號(hào)碼放在相應(yīng)的數(shù)組元素中. 程序運(yùn)行的界面如圖所示,實(shí)現(xiàn)上述功能的VB程序代碼如下: Dim a(10)As Single Private Sub Command1_Click ( ?。?br />Dim i As Integer,j As Integer Dim temp As Single,k As Integer‘temp產(chǎn)生隨機(jī)數(shù),k隨機(jī)數(shù)存放數(shù)組元素的下標(biāo) Randomize a(1)=Int(Rnd ( )*900+100) For i=2To 10 temp=Int(Rnd ( )*900+100) If seach(temp,i-1)=True Then i=i-1 Else
For j=-1To k Step-1 a(j+1)=a(j) Next j
End If Next i List1.Clear For i=1To 10 List1.AddItem Str(a(i)) Next i End Sub ‘函數(shù)實(shí)現(xiàn)在數(shù)組a中,從下標(biāo)為1的數(shù)組元素到下標(biāo)為t數(shù)組元素,查找有無(wú)pp的數(shù)值 Function seach(pp As Single,t As Integer) As Boolean Dim i As Integer seach=False For i=1To t If
Then seach=True:Exit For Next i End Function (1)程序中橫線處①應(yīng)填入