If Len(P)>1 And Len(P)>Len(sta) Then ______4_____ E1se
Max_st=sta End If End Function 【答案】(1)P = P + Mid(st, i + 1, 1)(2)p(3)P = Mid(st, i + 1, 1)(4)max_st = P 10.下面程序的功能是找出由两个不同的数字组成的回文平方数。程序界面参见图2。
Option Explicit
Private Sub Command1_Click()
Dim A(0 To 9) As Integer, I As Long, Flg As Boolean Dim L As Long, J As Integer, Sum As Integer For I=10 To 1000 L=I* I
____1_____
Call ____2____ If Flg then For J=0 To 9
Sum=Sum+A(J) Next J
If Sum=2 Then
List1. AddItem CStr(I) & \& Str(L)
End If
End If 图 2 Sum=0 Next I End Sub
Private Sub Sub1(byval X As Long, A()As Integer, BL As Boolean) Dim N As Integer, Idx As Integer, I As Integer BL=False
N=Len(CStr(X)) For I=1 To N/2
If _____3______ Then Exit Sub End If Next I BL=True For I=1 To N
Idx=X Mod 10 _____4______
X=(X\\10) Next I End Sub
【答案】(1)Erase A(2)Sub1(L, A, Flg)(3)Mid(CStr(X), I, 1) <> Mid(CStr(X), N - I + 1, 1)(4)A(Idx) = 1
11.下面程序的功能是随机生成10个不同的两位数,从中找出所有互质数对。若两个数除了1以外没有其他公约数,这两个数就是互质数。其中函数Rec是一个递归函数。程序界面参见图3。
Option Explicit
Private Sub Command1_Click()
Dim A(10)As Integer, I As Integer, J As Integer Dim N As Integer, K As Integer Randomize
A(1)=Int(90*Rnd)+10 Text1=A(1) _____1_____ Do _____2_____
N=Int(90*Rnd)+10 If _____3______ (Text1,CStr(N))=0 Then
Text1=Text1 & Str(N)
K=K+l 图 3 A(K)=N End If Loop
For I=1 To 9
For J=I+1 To 10
If Not Rec(A(I), A(J), 2) Then
List1.AddItem Str(A(I)) & Str(A(J)) End If Next J Next I End Sub
Private Function Rec(N As Integer, M As Integer, K As Integer)As Boolean If K>N Then _____4_____
E1se
If N Mod K=0 And M Mod K=0 Then Rec=True
_____5_____ E1se
_____6______ End If End If End Function 【答案】(1)k=1(2)While K < 10(3)InStr(4)Exit Function(5)Exit Function(6)Rec = Rec(N, M, K + 1)
12.执行下面程序,单击按钮Command1,窗体上显示的第一行是____1_____,第二行是____2____。
Private Sub Command1_Click()
Dim x As Integer, y As Integer, Z As Integer X=6: y=12: Z=20 Print fun1(x, y)
Print fun1(fun1(x, y), z) End Sub
Private Function fun1(a As Integer,b As Integer)As Long Dim Y As Integer Y=a DO
If y Mod b=0 Then Fun1=y
Exit Function Else
y=y +a End If Loop End Function 【答案】(1)12(2)60
13.执行下面程序,单击按钮Command1,窗体上显示的第一行是_____1_____,第二行是____2____。
Option Explicit Dim a As Single
Private Sub Command1_Click() Dim a As Single, b As Integer a=1. 2: b=3 Print fun1(a, b) Print a End Sub
Private Function fun1(x As Single, y As Integer)As Integer Dim i As Integer For i=1 To y x=x*2 a=a+1 Next i Fun1=a End Function 【答案】(1)3(2)9.6
14.执行下面程序后,单击按钮Command1,窗体上第一行显示的内容是____1____,第二行显示的内容是_____2____,第三行显示的内容是____3_____。
Private Sub Command1_Click()
Dim X As Integer, Y As Integer, S As Integer
X=12:Y=18 If X>Y Then
S=Recur(X, Y, 1) Else
S=Recur(Y, X, 1) End If Print S Print X, Y End Sub
Private Function Recur(A As Integer, B As Integer, K As Integer) Static X As Integer X=X+K
If A<=B Then Recur=A+B-X
Print \ Else
A=A-X B=B+X
Recur=Recur(A, B, X) End If X=0 End Function 【答案】(1)X=4(2)26(3)15 15 15.本程序利用级数法求解下面函数的近似值,规定当n取某一值时,若则停止运算。函数的级数展开式如下:
x2n?1n!≤0.0000l,
x3x5x7x2n?1f(x)?x????...??...
3?1!5?2!7?3!(2n?1)?n!Private Sub Command1_Click()
Dim X As Single, eps As Single X=Text1:eps=0.00001 Text2=fun(x, eps) End Sub
Private Function fun(x As Single, eps As Single)As Double Dim n As Integer, t As Double, Y As Double, S As Single Y=X:t=x
Do _____1____ N=n+1
S=_____2_____ T=_____3_____ Y=Y+S*t/(2*n+1) Loop fun=Y
End Function 【答案】(1)While Abs(t) > esp(2)(-1)^n(3)t*x^2/n 16.本程序是一个采用矩阵变换对西文进行加密的程序。取大于或等于原文长度的最小平方数n2,构造一个n×n的矩阵,将原文中的字符逐个按行写入该矩阵,多余的矩阵元素则写入空格字符,再按列读出此矩阵,即为密文。程序界面参见图l。
Option Explicit
Private Sub Command1_Click() Dim msg As String msg=Text1
Text2=encode(msg) End Sub
Private Function sr(n As Integer)As Integer
Dim k As Integer
k=n 图 1 Do
If _____1_____ Then Sr=Sqr(k):Exit Do
Else
_____2______ End If Loop
End Function
Private Function encode(orc As String)As String Dim n1 As Integer, n2 As Integer, m()As String*1 Dim i As Integer, j As Integer, k As Integer n1=Len(orc) n2=sr(n1) k=1
_____3_____ For i=l To n2 For J=l To n2 If k<=n1 Then
m(I, j)=Mid(orc, k, 1) Else
_____4_____
End If k=k+1 Next j Next i
For J=1 To n2 For i=1 To n2
encode=encode & m(I, j) Next i