vb第三部分 练习题

1.要使下列For语句循环执行20次,循环变量的初值应当是: 。

For k= 35 To -5 Step -2 2.执行下面的程序段后,s的值为 9 。

Private Sub Form_Click() s = 5

For i = 2.6 To 4.9 Step 0.6 s = s + 1 Next i Print s End Sub

3.下面程序段显示10 个“*”。

For i=l to 5

For J=2 To i

Print “*”; Next j Next i

4.以下程序段的输出结果是 1 2 3 。

Private Sub Command1_Click() num = 0 While num <= 2 num = num + 1 Print num Wend End Sub

5.以下程序段所对应的函数表达式是 。

X = InputBox(\X = CInt(X) Select Case X

Case Is <= 0 Y = 0 Case Is <= 10 Y = 5 + 2 * X Case Is <= 15 Y = X - 5 Case Is > 15 Y = 0 End Select 6.设有以下的循环:

X=l Do X=X+2 Print X

Loop Until x > =7 程序运行后,要求执行3次循环体,请填空。

7.下列第40句共执行了 12 次,第41句共执行了 12 次。

30 For j=1 To 12 Step 3 40 For k=6 To 2 Step -2 41 Print j,k 42 Next k 43 Next j

8.下面程序运行后输出的结果是 3 21 4 22 5 23 。

Private Sub Command1_Click() For i = 1 To 3

Print Tab(5 * i + 1); \ Next i End Sub

9.下面程序运行后输出的结果是 **$$$****$$$$$ 。

Private Sub Command1_Click() a$ = \ For i = 1 To 4 If i Mod 2 = 0 Then

X$ = String(Len(a$) + i, B$) Else

X$ = String(Len(a$) + i, a$) End If Print X$; Next i End Sub

10.执行下面程序,输出的结果是 13 -16 。

Option Explicit

Private Sub Form_Click() Dim i As Integer, j As Integer j = 10

For i = 1 To j Step 2 i = i + 1 j = j - i

Next i Print i, j End Sub

11.以下程序的功能是:从键盘上输入若干个学生的考试分数,统计并输出最高分数和最低分数,当输入负数时结束输入,输出结果,请填空。

Private Sub Form_Click() Dim X, amax, amin As Single X = InputBox(\ amax = X amin = X

Do While x>=0 If X > amax Then amax = X End If

If X

X = InputBox(\ Loop

Print \EndSub

12.阅读以下程序:

Private Sub Form_Click() Dim k, n, m As Integer n = 10 m = 1 k = 1

Do While k <= n m = m * 2 k = k + 1 Loop Print m End Sub

程序运行后,单击窗体,输出结果为 1024 。 13.阅读程序:

Private Sub Form_Click() Dim i As Integer, sum As Integer sum = 0

For i = 2 To 10

If i Mod 2 <> 0 And i Mod 3 = 0 Then sum = sum + i End If Next i Print sum End Sub

程序运行后,单击窗体,输出结果是 12 。 14.在窗体上画一个命令按钮,然后编写如下事件过程:

Private Sub Command1_Click() a = 0 For i = 1 To 2 For j = 1 To 4 If j Mod 2 <> 0 Then a = a十l End If a = a + 1 Next j Next i Print a End Sub

程序运行后,单击命令按钮,输出结果是 12 。

15.以下程序运行后,si、sj, sk、i、J、k的结果分别是 2 3 2 3 3 4 。 Private Sub Command1_Click()

si = 0: sj = 0: For i = 1 To 2 For j = 1 To i sk = 0 For k = j To 3 sk = sk + 1 Next k sj = sj + 1 Next j si = si + 1 Next i

Print si, sj, sk, i, j, k End Sub

16.输入任意长度的字符串,要求将字符顺序倒置,例如,将输入的“BCDEFG”变换成“GFEDCB”。

联系客服:779662525#qq.com(#替换为@)