江苏省计算机二级试题训练
18、执行下列程序,当单击窗体时,窗体上显示内容的第一行是 ,第三行 ,第七行 ,最后一行 。
Private Sub Form_Click()
Dim S As String, i As Integer, A(9) As Integer
Dim S1 As String * 1, j As Integer
S = Trim("136a637d28965f01b04c")
For i = 1 To Len(S)
S1 = Mid(S, i, 1)
If S1 >= "0" And S1 <= "9" Then
j = Val(S1)
A(j) = A(j) + 2
End If
Next i
For j = LBound(A) To UBound(A)
Print j; ":"; A(j)
Next j
End Sub
19、执行下面程序,单击窗体,显示在窗体上的第一行内容 ,第二行内容 ,第三行内容 ,最后一行内容 。
Dim N As Integer
Private Sub Form_Click()
Dim I As Integer, J As Integer
For I = 3 To I Step -2
N = Fun(I, N)
Print N
Next I
End Sub
Private Function Fun(A As Integer, B As Integer) As Integer
Static X As Integer
Dim Sum As Integer, I As Integer
X = X + N
For I = 1 To A
B = B + X + I
N = N - I \ 2
Sum = Sum + B
Next I
A = A + 1
Fun =Sum + A
End Function
20、下面的事件过程执行结束后,窗体上第一行显示 ,第二行显示 ,第三行显示 。
Private Sub Form_Click()
Dim A(3, 3) As Integer, I As Integer, J As Integer, K As Integer
I = 3: J = 1
A(I, J) = 10
For K = 11 To 18
If I + 1 > 3 Or J + 1 > 3 Then
If J = 1 Then
I = I - 1
ElseIf A(I - 1, J - 1) = 0 Then
I = I - 1: J = J - 1
ElseIf J = 3 Then
I = I - 1
Else
J = J + 1
End If
ElseIf J = 1 Or I = 1 Then
If A(I + 1, J + 1) = 0 Then
I = I + 1: J = J + 1
Else
J = J + 1
End If
Else
If A(I - 1, J - 1) = 0 Then
I = I - 1: J = J - 1
End If
End If
A(I, J) = K
Next K
For I = 3 To 1 Step -1
For J = 3 To 1 Step -1
Print Str(A(I, J));
Next J
Next I
End Sub
21、执行下面的程序,在窗体上显示的输出结果的第一行是 ,第二行是 ,第三行是 。
Private Sub Form_Click()
Dim N As Integer, M As Integer
N = 2
For M = 9 To 1 Step -1
Call Sub2(M, N)
Print M; N
Next M
End Sub
Private Sub Sub2(X As Integer, Y As Integer)
Static N As Integer
Dim M As Integer
For M = 3 To 1 Step -1
N = N + X
X = X - 1
Next M
Y = Y + N
End Sub
22、运行程序,单击命令按钮,窗体上输出结果是 。
Private Sub Command1_Click()
abc 2
abc 4
abc 9
End Sub
Private Sub abc(a As Integer)
Static X As Integer
X = X + a ^ 2
Print X;
End Sub
23、下列程序的功能是:计算ALL=1!+2!+3!+ … + n!(n=1,2,3…)其中n从键盘上输入。
Private Sub Command1_Click()
Dim i As Integer, Sum As Long, n As Long
Sum = 0
n = Val(InputBox("求n!的和,输入n:"))
For i = 1 To n
Sum = Sum + ( )
Next i
Print Sum
End Sub
Private Function Fun(k As Integer) As Long
Dim P As Long, i As Integer
P = 1
For i = 1 To k
P = P * i
Next i
( )
End Function
24、下面程序的功能是:验证任意一个大于5的奇数可表示为3个素数之和。完善程序,实现以上功能,程序界面参见右下图。
Option Base 1
Private Sub Command1_Click()
Dim P() As Integer, N As Integer, L As Integer
Dim I As Integer, J As Integer, K As Integer
Dim Ch As String
N = InputBox("输入一个大于5的奇数!")
Label1.Caption = CStr(N) & "="
Call Prime(P, N)
L = UBound(P)
For I = 1 To L
For J = 1 To L
For K = 1 To L
If P(I) + P(J) + P(K) = N Then
Ch = CStr(P(I)) & "+" & CStr(P(J)) & "+" & CStr(P(K))
Text1.Text = Ch
( )
End If
Next K
Next J
Next I
End Sub
Private Sub Prime( )
Dim I As Integer, Idx As Integer, J As Integer
For I = 2 To N
For J = 2 To Sqr(I)
If I Mod J = 0 Then Exit For
Next J
If( )Then
Idx = Idx + 1
( )
A(Idx) = I
End If
Next I
End Sub
25、下面程序模拟裁判评分(取某个范围内的随机数),设有10名裁判,打分范围为1到10,去掉一个最高分和一个最低分后,所得总分的平均分就是选手最后得分(四舍五入,保留1为小数)。程序界面参见下图。
Option Base 1
Private Sub Command1_Click()
Dim Score(10) As Single, i As Integer, Max As Single
Dim Min As Single, AV As Single, Sum As Single
For i = 1 To UBound(Score)
Score(i) = ( )
Text1 = Text1 & Str(Score(i)) & " "
( )
Next i
Call MaxMin(Score, Max, Min)
AV = (Sum - Max - Min) / 10
Text2 =( )
End Sub
Private Sub MaxMin(( ))
Dim i As Integer
Max = a(1): Min = a(1)
If a(i) > Max Then
Max = a(i)
ElseIf a(i) < Min Then
Min = a(i)
End If
Next i
End Sub
26、C盘根目录下的数据文件data.txt中有两组数据,第一组数据未排序,并以-1表示该组数据结束;第二组数据按从小到大顺序排序。下面程序的功能是,单击“读入数据”按钮,将文件中的两组数据,分别读入到A、B数组中,单击“插入排序”按钮,则把A数组的元素按其大小依次插入到B数组的适当位置,使得B数组中元素仍为从小到大排列。完善程序,实现以上功能。程序界面参见下图。
Dim a() As Integer, b() As Integer
Private Sub Command1_Click()
Dim i As Integer, j As Integer, n As Integer, s As String
( )
Do
Input #11, n
If n = -1 Then Exit Do
i = i + 1
ReDim Preserve a(i)
a(i) = n
s = s & Str(a(i))
Loop
Text1 = s
s = ""
( )
j = j + 1
ReDim Preserve b(j)
Input #11, b(j)
s = s & Str(b(j))
Loop
Text2 = s
Close #11
End Sub
Private Sub Command2_Click()
Dim i As Integer, j As Integer, s As String
For i = 1 To UBound(a)
If a(i) < b(1) Then
Call change(a(i), 1)
ElseIf a(i) > b(UBound(b)) Then
(
b(UBound(b)) = a(i)
Else
For j = 2 To UBound(b)
If a(i) > b(j - 1) And a(i) <= b(j) Then Call change(a(i), j)
Next j
End If
Next i
For i = 1 To UBound(b)
s = s & Str(b(i))
Next i
Text3 = s
End Sub
Private Sub change(n As Integer, k As Integer)
Dim i As Integer
ReDim Preserve b(UBound(b) + 1)
For i = UBound(b) To k + 1 Step -1
( )
Next I
( )
End Sub
27、执行下面的程序,单击Form1,则图片框中显示的第一行是 ,第二行 ,最后一行 。
Private Sub Form_Click()
Dim a(3, 3) As Integer, i As Integer, j As Integer
For i = 1 To 3
For j = 3 To 1 Step -1
If i >= j Then
a(i, j) = i - j
Else
a(i, j) = j - i
End If
Next j
Next i
For i = 1 To 3
For j = 3 To 1 Step -1
Picture1.Print a(i, j);
Next j
Picture1.Print
Next i
End Sub
28、执行下面的程序,单击窗体,在窗体上显示的变量A的值为 ,变量B的值为 。
Dim A As Integer
Private Sub Form_Click()
Dim B As Integer
B = 3: A = 4
B = Fun(Fun(A, B + 3), A) + B
Print A, B
End Sub
Private Function Fun(N As Integer, K As Integer)
N = N + A: K = N - K: Fun = N + K + A
End Function
29、执行下面程序,单击Form1,窗体上显示的第一行是 ,第二行是 ,第三行是 。
Private Sub Form_Click()
Dim I As Integer, n As Integer
For I = 5 To 15 Step 2
n = Fun1(I, I)
Print n
Next I
Print I
End Sub
Private Function Fun1(ByVal a As Integer, b As Integer)
b = a + b: a = b - a: Fun1 = a + b
End Function
更多计算机二级相关试题分享: