第6章習(xí)題
一、單選題
D 2. A 3.(1)B,(2)B
4.C 5. C 6. A
7. (1)C (2)B (3)A (4)B (5)D
二、多選題
1. AD 2. CD
三、填空題
12; 1, 3; -1, 2 2. 0 1 2 3
2 2 2 2
2 1 0 1
4 4 4 4
3. Name, Index
4.
(1) 0 To Index
(2)Val(Text1(k).Text)
5.
(1) i+1 To k
(2) s(i)< s(j)
(3) s(i)<>s(i-1)
(4) h = h+1
6. (1) ReDim a(1 To n + 1)
(2) a(K + 1) = a(K) (3) a(p)
編程及上機(jī)調(diào)試
1. 程序代碼如下:
Private Sub Form_Load()
Show
Dim a(100) As Single
n = Val(InputBox("輸入個(gè)數(shù)n"))
Print "處理前數(shù)據(jù) :"
For k = 1 To n
a(k) = Val(InputBox("請(qǐng)輸入第" & k & "個(gè)數(shù)"))
Print a(k);
Next k
M = Int(n / 2)
For k = 1 To M
h = n - k + 1
t = a(h):a(h) = a(k):a(k) = t
Next k
Print "處理的結(jié)果 :"
For k = 1 To n
Print a(k);
Next k
End Sub
2. 程序代碼如下:
Private Sub Form_Load()
Dim a(6, 6) As Integer
Show
For i = 1 To 6
For j = 1 To 6
Select Case i
Case Is < j
a(i, j) = 1
Case Is > j
a(i, j) = 2
Case Is = j
a(i, j) = 0
End Select
Print a(i, j);
Next j
Next i
For i = 1 To 6
t = a(1, i):a(1, i) = a(6, i):a(6, i) = t
Next i
Print: Print
For i = 1 To 6
For j = 1 To 6
Print a(i, j);
Next j
Next i
End Sub
3.在窗體上建立兩個(gè)列表框List1(處理前數(shù)據(jù))和List2(處理后數(shù)據(jù)),以及標(biāo)簽Label1。程序代碼如下:
Private Sub Form_Load()
Dim a(100) As Integer, b(100) As Integer
Randomize
n = 100
For i = 1 To n '輸入數(shù)組a的n個(gè)元素
x = Int(20 * Rnd)
List1.AddItem x
a(i) = x
Next i
k = 0
For i = 1 To n '刪除零元素
If a(i) <> 0 Then
k = k + 1 : b(k) = a(i) : List2.AddItem b(k)
End If
Next i
Label1.Caption = "數(shù)組中零元素個(gè)數(shù):" + Str(n - k)
End Sub
4.(1) g(x - 10) + 1 (2) n - 1 (3) g(t) < g(j)
(4) m = s(t): s(t) = s(k): s(k) = m
5.在窗體上建立4行3列共12個(gè)元素的文本框控件數(shù)組Text1(0)~Text1(11)
Private Sub Form_Load()
Dim t(12) As String
Randomize
For k = 1 To 12
t(k) = "Empty" '初始安排12個(gè)位置均為"Empty"
Next k
For h = 65 To 74 '代表"A"至"J",每次隨機(jī)安排一個(gè)字母
Do While True '隨機(jī)查找一個(gè)空位
p = Int(1 + 12 * Rnd) '產(chǎn)生1~12隨機(jī)數(shù)
If t(p) = "Empty" Then
t(p) = Chr(h)
Exit Do
End If
Loop
Next h
For k = 1 To 12
Text1(k - 1).Text = t(k) '顯示座位分配情況
Next k
End Sub