内容发布更新时间 : 2025/2/7 20:12:39星期一 下面是文章的全部内容请认真阅读。
2009年(秋)上机 Visual Basic(VB03)答案
一、改错
【题目】本程序的功能是,找出所有两位整数中的“镜反平方数对”。 Option Explicit
Private Sub Command1_Click()
Dim n As Integer, fn As Integer, st As String For n = 11 To 99
If InStr(CStr(n), \ 'err <> 0 fn = fx(n)
If validate(n, fn) And n <> fn Then
st = n & \ List1.AddItem st End If End If Next n
If List1.ListCount = 0 Then List1.AddItem \无镜反平方数\End Sub
Private Function fx(ByVal n As Integer) As Integer 'err 无ByVal Dim s As String Do
s = s & CStr(n Mod 10) 'err s & Str(n Mod 10) n = n \\ 10 Loop Until n = 0 fx = s End Function
Private Function validate(p As Integer, q As Integer) As Boolean If fx(p ^ 2) = q ^ 2 Then validate = True End If End Function 二、编程题
【题目】编写程序,找出输入字符串中ASCII代码值最大的字符,把它移动到原字符串的末尾,其他字符的排列顺序维持不变。 Option Explicit
Private Sub Command1_Click()
Dim st1 As String, st2 As String, sa() As String * 1
Dim i As Integer, n As Integer, mc As String * 1, k As Integer st1 = Text1 n = Len(st1) ReDim sa(n) For i = 1 To n
sa(i) = Mid(st1, i, 1) Next i
Call maxc(sa, mc, k) For i = k To n - 1
Mid(st1, i, 1) = Mid(st1, i + 1, 1) Next i
st2 = Left(st1, n - 1) & mc Text2 = st2 End Sub
Private Sub maxc(a() As String * 1, c As String, k As Integer) Dim i As Integer c = a(1) k = 1
For i = 2 To UBound(a)
If Asc(a(i)) > Asc(c) Then c = a(i) k = i End If Next i End Sub
Private Sub Command2_Click() Text1 = \ Text1.SetFocus End Sub
Private Sub Command3_Click() End End Sub