Print \小写字母个数为:\ Print \其他字符个数为:\End Sub
4.
Private Sub Form_Click()
Dim n As Integer, sum As Integer
n = Val(InputBox(\请输入一个正整数:\ Do Until n = 0
sum = sum + n Mod 10 n = n \\ 10 Loop
MsgBox (\各位数字之和为:\End Sub 5.
Private Sub Form_Click()
Dim n As Long, i As Integer, L As Integer n = Val(InputBox(\请输入一个正整数:\ L = Len(CStr(n)) For i = 1 To L / 2
If Mid(CStr(n), i, 1) <> Mid(CStr(n), L, 1) Then Exit For End If L = L - 1 Next i
If i > L / 2 Then
MsgBox (\该数是回文数。\ Else
MsgBox (\该数不是回文数。\ End If End Sub 6.
Private Sub Command1_Click()
Dim a As Integer, b As Integer, c As Integer For a = 1 To 30 For b = 1 To 30 For c = 1 To 30
If a ^ 2 + b ^ 2 = c ^ 2 And a < b Then Print a, b, c End If Next c Next b
Next a End Sub
第五章 数组
一.单选题
1. B 2. C 3. B 4. B 5. D 6. D 7. A 8. B 二.编程题
1.
Option Base 1
Private Sub Command1_Click()
Dim a(15) As Integer, i As Integer, j As Integer Do
j = Int(Rnd * 90) + 10 If j Mod 2 <> 0 Then i = i + 1 a(i) = j
Label1.Caption = Label1.Caption & Str(a(i)) End If
Loop Until i = 15 For i = 1 To 14
For j = i + 1 To 15 If a(i) < a(j) Then t = a(i) a(i) = a(j) a(j) = t End If Next j
Label2.Caption = Label2.Caption & Str(a(i)) Next i
Label2.Caption = Label2.Caption & Str(a(i)) End Sub 2.
Option Base 1
Private Sub Form_Click()
Dim a(10) As Integer, i As Integer, Max As Integer, Min As Integer, sum As Integer For i = 1 To 10
a(i) = Int(Rnd * 90) + 10 Print a(i);
sum = sum + a(i) Next i Print
Max = a(1) Min = a(1) For i = 2 To 10
If a(i) > Max Then Max = a(i)
ElseIf a(i) < Min Then Min = a(i) End If Next i
Print \最大数为:\ Print \最小数为:\ Print \平均值为:\End Sub
3.
Private Sub Form_Click()
Dim a(0 To 25) As Integer, idx As Integer, i As Integer, S As String, ch As String * 1 S = InputBox(\请输入一个字符串:\ Print \输入的字符串为:\ For i = 1 To Len(S) ch = Mid(S, i, 1)
If ch >= \ idx = Asc(ch) - Asc(\ a(idx) = a(idx) + 1
ElseIf ch >= \ idx = Asc(ch) - Asc(\ a(idx) = a(idx) + 1 End If Next i
Print \统计结果如下:\ For i = 0 To 25
Print Chr(Asc(\次\ Next i End Sub 4.
Option Base 1
Private Sub Form_Click()
Dim a() As Integer, m As Integer, n As Integer Dim i As Integer, j As Integer, Max As Integer m = Val(InputBox(\请输入行数:\ n = Val(InputBox(\请输入列数:\ ReDim a(m, n) For i = 1 To m For j = 1 To n
a(i, j) = Int(Rnd * 90) + 10 Print a(i, j);
If a(i, j) > Max Then Max = a(i, j) Next j Print Next i Print
For i = 1 To m For j = 1 To n
If a(i, j) = Max Then
Print \最大元素是:\ Print \行号:\ Print \列号:\ End if Next j Next i End Sub
5.
Option Base 1
Private Sub Form_Click()
Dim a(5, 5) As Integer, i As Integer, j As Integer
Dim sum1 As Integer, sum2 As Integer, sum3 As Integer Print \随机生成数组元素.\ For i = 1 To 5 For j = 1 To 5
a(i, j) = Int(Rnd * 9) + 1 Print a(i, j);
sum3 = sum3 + a(i, j)
If i = 1 Or i = 5 Or j = 1 Or j = 5 Then sum2 = sum2 + a(i, j) End If Next j Print Next i
For i = 1 To 5
sum1 = sum1 + a(i, i) + a(i, 6 - i) Next i
sum1 = sum1 - a(3, 3)
Print \对角线元素之和为:\ Print \所有靠边元素之和为:\ Print \所有数组元素之和为:\End Sub
6.
Option Base 1
Private Sub Form_Click()
Dim a() As Integer, b() As Integer, n As Integer, k As Integer, i As Integer, j As Integer n = Val(InputBox(\请输入n=\ ReDim a(n + 1, n + 1), b(n + 1, n + 1) k = 8
For i = 1 To n For j = 1 To i a(i, 1) = 1 a(i, i) = 1
a(i + 1, j + 1) = a(i, j) + a(i, j + 1) b(i, j) = a(i, j) Print b(i, j); \ Next j Print Next i End Sub
第六章 过程
一.填空题
1. 2. 3.
AFBECD -5 5 2 4 6 8 33 5
4. 5.