VB实验教材习题答案 (1)
- 1、下载文档前请自行甄别文档内容的完整性,平台不提供额外的编辑、内容补充、找答案等附加服务。
- 2、"仅部分预览"的文档,不可在线预览部分如存在完整性等问题,可反馈申请退款(可完整预览的文档不适用该条件!)。
- 3、如文档侵犯您的权益,请联系客服反馈,我们会尽快为您处理(人工客服工作时间:9:00-18:30)。
第1章VB集成环境与VB概述一、选择题
第2章常用控件与界面设计一、选择题
第3章数据、表达式与简单程序设计一、选择题
第4章选择分支与循环
一、选择题
二、填空题
1.5 7 13 12 14 11
2. 3 1 5 3 4 1
3. right(a$,i)
4. 4
5. 6-i
6. 6 11 10 21 13 34
7. 5 14 13
8. Is else end select
9. a*(2*i-1)*(-1)*x/(2*i+2) i+1
10. 0 n-1
11. 1 t*(-1)*x^2/((2*k-1)*(2*k)) Abs(t)>eps
12. count1=count+1 count1>0
13. sum=0 sum+j st & k & “+”
14. 9 x
三、编程题
1.
Option Explicit
Private Sub Command1_Click()
Dim s As String, i As Integer, ch As String * 1
Dim a As Integer, b As Integer, c As Integer
s = Text1.Text
For i = 1 To Len(s)
ch = Mid(s, i, 1)
If (ch >= "0" And ch <= "9") Then
a = a + 1
ElseIf (ch >= "A" And ch <= "Z") Or (ch >= "a" And ch <= "z") Then
b = b + 1
Else
c = c + 1
End If
Next
Print "数字个数"; a
Print "字符个数"; b
Print "其他字符"; c
End Sub
2.
Option Explicit
Private Sub Command1_Click()
Dim i As Integer, n As Integer
Dim a As Integer, b As Integer, c As Integer
For i = 1 To 50
n = Int(Rnd * 90 + 10)
Print n;
If i Mod 10 = 0 Then Print
If n <= 40 Then
a = a + 1
ElseIf n <= 70 Then
b = b + 1
Else
c = c + 1
End If
Next i
Print "小于等于40的个数:"; a
Print "大于40小于等于70的个数:"; b
Print "大于70的个数:"; c
End Sub
3.
Option Explicit
Private Sub Command1_Click()
Dim x As Single
Dim t As Long, n As Integer
x = 1
t = 1
n = 1
Do While 1 / t >= 0.0001
x = x + 1 / t
n = n + 1
t = t * n
Loop
Print x
End Sub
4.
Option Explicit
Private Sub Command1_Click()
Dim k As Integer, sum As Integer, i As Integer
k = InputBox("请输入一个正整数k", "输入框")
For i = 1 To Len(CStr(k))
sum = sum + Mid(k, i, 1)
Next i
MsgBox k & "的各位数字之和" & sum
End Sub
5.
Option Explicit
Private Sub Command1_Click()
Dim i As Integer, iSum As Long
For i = 1 To 20
iSum = iSum + i ^ 4
Next
Print iSum
End Sub
6.
Option Explicit
Private Sub Command1_Click()
Dim a As Integer, b As Integer
Dim sum1 As Integer, sum2 As Long
Dim i As Integer, j As Integer
For a = 2 To 3000
sum1 = 0
sum2 = 0
For i = 1 To a \ 2
If a Mod i = 0 Then sum1 = sum1 + i Next i
b = sum1
For j = 1 To b \ 2
If b Mod j = 0 Then sum2 = sum2 + j Next j
If sum2 = a And a < b Then Print a, b
Next
End Sub
7.
Private Sub Command1_Click() '打印菱形
Dim i As Integer, j As Integer
Cls
For i = 1 To 6 '打印菱形上边6行
Print Tab(20);
Print Spc(6 - i);
For j = 1 To 2 * (i - 1) + 1
If j = 1 Or j = 2 * (i - 1) + 1 Then
Print "*";
Else
Print " ";
End If
Next j
Next i
For i = 5 To 1 Step -1 '打印下半部分
Print Tab(20);
Print Spc(6 - i);
For j = 1 To 2 * (i - 1) + 1
If j = 1 Or j = 2 * (i - 1) + 1 Then