實(shí)現(xiàn)上述功能的 VB 程序如下,但加框處代碼有錯(cuò),請改正。 Const n=10 Dim a(1 To n) As Integer Private Sub Command1_Click ( ) Dim i As Integer,j As Integer Dim temp As Integer,flag As Boolean '讀取一組正整數(shù),存儲在數(shù)組 a 中,代碼略 i=1:j=n temp=a(j):flag=True Do While i<j If flag Then If =0 Then a(j)=a(i) j=j-1 flag=Not flag Else j=j-1'(1) End If
If a(j) Mod 2=1 Then a(i)=a(j) flag=Not flag Else j=j-1 End If End If Loop a(i+j)=temp'(2) '依次輸出排序后的數(shù)據(jù),代碼略。 End Sub
。 (2)實(shí)現(xiàn)上述功能的VB程序如下,請?jiān)跈M線處填入合適的代碼。 Const n=10 Dim i As Integer,j As Integer,t As Integer Dim a(1 To n) As Integer Private Sub Form_Load ( ) '本過程用于讀取n堆的數(shù)據(jù)并存儲在數(shù)據(jù)a中 '代碼略 End Sub 'sort(x)過程的功能是對a(x)、a(x+1)、……、a(n)中的數(shù)進(jìn)行從小到大排序 Private Sub sort(x As Integer) For i=
To n-1 For j=n To i+1 Step-1 If a(j)<a(j-1)Then t=a(j):a(j)=a(j-1):a(j-1)=t End If Next j Next i End Sub Private Sub Command1_Click ( ) Dim sum As Integer,k As Integer sum=0 sort (1) For k=1 To n-1 a(k+1)=a(k)+a(k+1) sum=sum+