For i = 1 To Len(s) ch = Mid(s, i, 1)
If \ If Asc(ch) - k < Asc(\
Mid(s, i, 1) = Chr(Asc(ch) - k + 26) '小于A的ASCII值则加上26 Else
Mid(s, i, 1) = Chr(Asc(ch) - k) End If
ElseIf ch >= \ '多分支格式,ch介于小写a与z之间 If Asc(ch) - k < Asc(\
Mid(s, i, 1) = Chr(Asc(ch) - k + 26) '小于a的ASCII值则加上26 Else
Mid(s, i, 1) = Chr(Asc(ch) - k) End If End If Next i End Sub 实验6-4
1、 b() As Integer, st As String 2、 L <= R
3、 ReDim Preserve b(R) 4、 L = L + 1
辗转相除法求最大公约数函数
Private Function Gcd(ByVal p As Integer, ByVal q As Integer) As Integer
Dim r As Integer r = p Mod q Do While r <> 0 p = q q = r
r = p Mod q Loop Gcd = q End Function 实验 6-5 【题目一】
age = age(n - 1) - 3 【题目二】
1、(Left + Right) / 2 2、Left = Mid + 1 实验6-6 1、3 -1 2、7 4
3、3 -1 4、7 0 实验6-7 【题目一】
1、 Sqr(2 + t)
2、 Abs(a - 1) < eps 【题目二】
1、 Dim X As Integer 2、 \3、 (j * i + 1)
习题参考答案
一 选择题
1. B 11. D 21. C 2. D 12. A 22. C 3. C 13. A 23. B 4. C 14. A 24. A 5. D 15. B 25. D 6. B 16. B 26. D 7. B 17. D 27. A 8. B 18. C 28. B 9. A 19. D 10. D 20. B 二、填空
1(1) 形式 、(2) 实在 2(1) 按地址传递 、(2) ByVal 3(1) 窗体模块 、(2) 标准模块 、(3) 类模块 4(1) 6 5(1)4 20 101 6(1) 6 26 、(2) -2 98 7(1) 10 6 、(2) 5 -5 8(1) 6 5 、(2) 8 7 9(1) 11 、(2) 7 10(1) Fun(i) 、(2) Fun=p 11(1) 4 、(2) 20.7 12(1) 29 、(2) 28.7 13(1) k = j 、(2) b() As Integer 14(1) gec 、(2) ge 、(3) 3 15(1) p1 = True And p2 = True 或 p1 And p2 、(2) p1 = p2 – 2 、
(3) Isp = True 、(4) m Mod i = 0 16(1) Convert(st) 、(2) Len(s) 、
(3) \ 、(4) k = k + p * h 17(1) isualVi 、(2) sualVisu 18(1) s + a 、(2) n + 1 、
(3) x As Single, n As Integer 、(4) p * (x + i) / ((2 * i - 1) * i * x)
三、改错题
1、
Option Base 1
Private Sub Command1_Click()
Dim A() As Integer, I As Integer, J As Integer, Logic As Boolean Dim K As Integer ReDim A(1) A(1) = 50
———————— 'K=1 For I = 51 To 149 K = 1 '位置错 Logic = False
Call Sub1(A, I, Logic) If Logic Then K = K + 1
ReDim A(K) 'ReDim Preserve A(K) A(K) = I End If Next I
For I = 1 To UBound(A)
Text1 = Text1 & Str$(A(I))
If I Mod 5 = 0 Then Text1 = Text1 & vbCrLf Next I End Sub
Private Sub Sub1(A() As Integer, N As Integer, F As Boolean) Dim I As Integer, J As Integer, Ub As Integer Ub = UBound(A) For I = 1 To Ub
For J = 2 To A(I)
If A(I) Mod J = 0 And N Mod J = 0 Then
Exit For 'Exit Sub End If Next J F = True Next I End Sub 2、
Option Explicit Option Base 1
Private Sub Command1_Click()
Dim I As Integer, Flg As Boolean, S1 As Integer, S2 As Integer Dim J As Integer, K As Integer, P() As Integer ReDim P(1) P(1) = 2
For I = 3 To 150 Step 2 For J = 2 To Sqr(I)
If I Mod J = 0 Then Exit For Next J
If J > Sqr(I) Then
ReDim Preserve P(UBound(P) + 1)
P(UBound(P) + 1) = I 'P(UBound(P)) = I End If Next I
For I = 80 To 125
If fun(I, P, S1, S2) Then 'If fun(I, P, S1, S2)
Text1 = Text1 & Str$(I) & \ End If Next I End Sub
Private Function fun(N As Integer, P() As Integer, S1 As Integer, S2 As Integer) As Boolean Dim I As Integer, J As Integer For I = 1 To UBound(P)
For J = 1 To UBound(P) - 1 If N = P(I) * P(J) Then S1 = P(I) S2 = P(J)
'fun = True Exit Function fun = True '位置错 End If Next J Next I
End Function 3、
Option Explicit
Private Sub Get_Chess(Chess() As Integer, idx As Integer, Over As Integer) 'ByVal idx As Integer
Dim Ub As Integer, Counter As Integer, K As Integer Ub = UBound(Chess) Chess(idx) = 0 Counter = 1 K = 0 '位置错 Do Until Counter = Ub - 1 Do Until K = 2 idx = idx + 1
If idx > Ub Then idx = 1 K = K + Chess(idx) Loop
Chess(idx) = 0
Counter = Counter + 1 Loop
For Over = 1 To Ub
If Chess(Over) <> 0 Then Exit For Next Over End Sub
Private Sub Command1_Click()
Dim Chess(32) As Integer, I As Integer, J As Integer Dim K As Integer, idx As Integer For I = 1 To 32
For J = 1 To 32 Chess(J) = 1 Next J
Call Get_Chess(Chess, I, K) If K = 23 Then
Text1 = \从第\号棋子开始取\ Exit For End If Next I End Sub 5、
Option Explicit