回覆列表
  • 1 # 長頸鹿大熊貓

    2、將窗體Form1的caption屬性改為“選擇法陣列排序”,將介面設定成下圖。

    3、在Load事件中寫入如下程式碼。RandomizeFor i = 1 To 10a(i) = Int(Rnd * 101 + 100)Lbl1.Caption = Lbl1.Caption & a(i) & " "Next i。

    4、在通用對話方塊對陣列進行定義,使其成為窗體級變數:Dim a(1 To 10) As Integer。

    5、雙擊“升序排列”命令按鈕,進入程式碼編輯視窗,輸入如下程式碼:For i = 1 To 9Min = a(i)For j = i + 1 To 10If a(j) < Min ThenMin = a(j)t = a(i): a(i) = a(j): a(j) = tEnd IfNext jNext iLbl2.Caption = ""For i = 1 To 10Lbl2.Caption = Lbl2.Caption & a(i) & " "Next i。

    6、雙擊“降序排列”命令按鈕,進入程式碼編輯視窗,輸入如下程式碼:For i = 1 To 9Max = a(i)For j = i + 1 To 10If a(j) > Max ThenMax = a(j)t = a(i): a(i) = a(j): a(j) = tEnd IfNext jNext iLbl2.Caption = ""For i = 1 To 10Lbl2.Caption = Lbl2.Caption & a(i) & " "Next i。

    7、關閉程式碼視窗,按下F5執行程式,產生10個隨機數,標籤中顯示10個數。

  • 中秋節和大豐收的關聯?
  • 靜心養身是什麼意思?