一、選擇題:
1—10: DCBBDDDBCB
二、填空題
1.a Ubound(b) n=n-1
2.Key=a(i) Index=-1
三、編程題
1.子過程
Sub P1(x As Single, esp As Single)
Dim p!,S!,F!,i%
P=1:S=1:i=1:F=x
Do
P=P*i
S=S+F/p
Loop Until Abs(F/p)<ESP Print s
End Sub
子函數(shù)
Function P2(x As Single, esp As Single) As single
Dim p!,S!,F!,i%
P=1:S=1:i=1:F=x
Do
P=P*i
S=S+F/p
Loop Until Abs(F/p)<ESP P2=s
End Function
2.Swap2能實現(xiàn)數(shù)據(jù)交換。因為地址傳遞方式形參和實參有共同的地址,那么形參的變化,會引起實參的變化(即形參將值回傳給實參),故可實現(xiàn)兩數(shù)交換。
3.Function LF( ByVal x As Single) As Single
LF=X*X*X
End Function
Sub Command1_Click()
Dim I%
For i=1 To 20
Print I, LF(i)
Next i
End Sub
4.Function WeekDay(ByVal x As Integer) As String
Select Case x
Case 0
WeekDay=”星期日”
Case 1
WeekDay=”星期一”
Case 2
WeekDay=”星期二”
Case 3
WeekDay=”星期三”
Case 4
WeekDay=”星期四”
Case 5
WeekDay=”星期五”
Case 6
WeekDay=”星期六”
End Select
End Function
5.Function Rand30(ByVal X As`Integer) As Integer
Randomize
Rand30=Int(Rnd*X+1)
End Function
Sub Command1_Click()
For i=1 To 30
Print Rand30(100)
Next i
End Sub
6.Function F1(ByVal X As`Single, ByVal Y As`Single) As Integer
If X>Y Then
F1=X
Else
F1=Y
End If
End Function
7.
Function GDBH(ByVal x%) As String
Dim i%
For i = 3 To x - 3 Step 2
If isp(i) And isp(x - i) Then
GDBH = i & "+" & (x - i) & "=" & x
Exit Function
End If
Next
End Function
Function isp(y%) As Boolean
i = 2: k = Int(y / 2)
Do While i <= k
If y Mod i = 0 Then Exit Do
i = i + 1
Loop
If i > k Then
isp = True
Else
isp = False
End If
End Function
Private Sub Form_Click()
For i = 6 To 40 Step 2
Print GDBH(i)
Next i
End Sub
8.Function isQO(ByVal x As Integer) As String
If x Mod 2 =0 Then
isQO=”偶數(shù)”
Else
isQO=”奇數(shù)”
End If
End Function
9.Function F1(ByVal x As Integer) As Boolean
If x Mod 17 =0 and x Mod 37 =0Then
F1=True
Else
F1=False
End If
End Function
Private Sub Form_Click()
For i = 1000 To 2000
If F1(i) Then
Print i
End if
Next i
End Sub
10.Sub F1(a() As Integer, ByVal L1 As Integer, ByVal L2 As
Integer)
Dim L%, U%, x%, i%
L = LBound(a): U = UBound(a)
If L1 > U Or L2 > U Then
Print "位置輸入錯誤!"
Exit Sub
End If
If L1 > L2 Then
x = a(L1)
For i = L1 To L2 + 1 Step -1
a(i) = a(i - 1)
Next i
a(L2) = x
ElseIf L2 > L1 Then
x = a(L1)
For i = L1 To L2 - 1
a(i) = a(i + 1)
Next i
a(L2) = x
End If
End Sub