For j=1 To i X=x+1 Next j Next i Print x End Sub
程序运行后,单击命令按钮,如果输入3,则在窗体上显示的内容是________。 (A)3 (B)4 (C)5 (D)6 17.以下能够正确计算n!的程序是________。
(A) Private Sub Command1-Click() N=5:x=1 Do
X=x*1 I=i+1
Loop While i (B) Private Sub Command1-Click() N=5:x=1:i=1 Do X=x*i I=i+1 Loop While i (C) Private Sub Command1-Click() N=5:x=1:i=1 Do X=x*i I=i+1 Loop While i<=n Print x End Sub (D) Private Sub Command1-Click() N=5:x=1:i=1 Do X=x*i I=i+1 Loop While i>n Print x End Sub 18.下列程序的运行结果是________。 s=O:t=O:u=O For x=1 To 3 - 48 - For y=1 To x For z=y To 3 s=s+1 Next z t=t+1 Next y u=u+1 Next x Print s;t;u (A) 3 6 14 (B) 14 6 3 (C) 14 3 6 (D) 16 4 3 二. 填空题 1. 要使下列For语句循环执行20次,循环变量的初值应当是: For k = ________ To – 5 Step – 2 2. 下面程序段要显示________个“*”。 For i = 1 To 5 For j = 2 To i Print"*"; Next j Next i 3. 下列第40句共执行了________次,第41句共执行了________次。 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 4. 以下程序运行后,si、sj、sk、i、j、k的结果分别是________、________、________、 ________、________、________。 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 5. 下面程序运行后输出的结果是________。 Private Sub Command1_Click( ) For i = 0 To 3 - 49 - Print Tab(5 * i + 1);"2" + i;"2" & i; Next i End Sub 6. 下面程序运行后输出的结果是________。 Private Sub Command1_Click( ) a$ = "*":B$ = "$" 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 7. 执行下面程序,打印的结果是________。 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 8. 输入任意长度的字符串,要求将字符顺序倒置,例如,将输入的"ABCDEFG"变换成" GFEDCBA"。 Private Sub Command1_Click( ) Dim a$,I$,c$,d$ a = InputBox$("输入字符串") n = ________ For i = 1 To ________ c = Mid(a,i,1) Mid(a,i,1) = ________ ________ = c Next i Print a End Sub 9. 找出被3、5、7除,余数为1的最小的5个正整数。 Private Sub Command1_Click( ) Dim CountN%,n% CountN = 0 n = 1 - 50 - Do n = n + 1 If ________ Then Print n CountN = CountN + 1 End If Loop ________ End Sub 10. 某次大奖赛,有七个评委打分,如下程序对一名参赛者,输入七个评委的打分分数,去 掉一个最高分、一个最低分后,求出平均分为该参赛者的得分。 Private Sub Command_Click( ) Dim mark!,aver!,i%,max1!,min1! aver = 0 For i = 1 To 7 mark = InputBox("输入第"& i &"位评委的打分") If i = 1 Then max1 = mark: ________ Else If mark < min1 Then ________ ElseIf mark > max1 Then ________ End If End If ________ Next i aver = ________ Print aver End Sub 11. 由键盘输入一个正整数,找出大于或等于该数的第一个质数。 Private Sub Command_Click( ) Dim m%,x%,Tag As Boolean Tag = False x = InputBox("输入正整数") Do While Not Tag m = 2 : Tag = ________ Do While Tag And (m<(x \\ 2) ) If x Mod m = 0 Then ________ Else ________ Loop If Not Tag Then x = x + 1 Loop Print x End Sub 12. 将一个正整数分解为质因数相乘。例如,234 = 2 * 3 * 3 * 13。 - 51 -