Const n=7 Dim a(-1To n) As Integer Private Sub Form_Load ( ?。?br />'隨機(jī)生成7個(gè)不重復(fù)的正整數(shù)到a
數(shù)組中。代碼略 End Sub Private Sub Command1_Click ( ?。?br />Dim mid As Integer,end1As Integer Dim i As Integer,j As Integer,num As Integer mid=0:end1=0 Do While end1<=n
j=end1 If num Mod 2=1Then Do While a(j)=a(j-1) j=j-1 Loop a(j)=num mid=mid+1 Else Do While a(j-1)>num And j-1>=mid a(j)=a(j-1) j=j-1 Loop a(j)=num End If end1=end1+1 Loop For i=0To n List1.AddItem Str(a(i)) Next i End Sub
(2)請(qǐng)?jiān)跈M線處填入合適的代碼。 Dim a(1To 30)As Integer Private Sub Form_Load ( ?。?br />'隨機(jī)生成30個(gè)不重復(fù)的正整數(shù)到a
數(shù)組中。代碼略 End Sub Private Sub Command1_Click ( ?。?br />Dim t As Integer,i As Integer,m As Integer,j As Integer,x As Integer Dim s As String,tt As String Dim start As Integer'當(dāng)前數(shù)字方陣的第1個(gè)元素下標(biāo) m=Val(Text1.Text) t=30\m^2 If t=0Then MsgBox“重新輸入“ Else List1.Clear For i=1To t start=
For j=1To m For x=1To m tt=tt+
Next x List1.AddItem tt tt=““ Next j List1.AddItem““ s=sum1(start,m) List2.AddItem“第“+Str(i)+“組的對(duì)角線分別是:“+s Next i End If End Sub Function sum1(begin As Integer,m As Integer) As String Dim s1As Integer,s2As Integer s1=a(begin) For i=1To m-1 s1=s1+a(begin+i*(m+1)) Next i s2=0 For i=1To m s2=s2+a(begin+i*(m-1)) Next i sum1=