Function huiwen(x)
m = Len(x)
For i = 1 To m / 2
If Mid(x, i, 1) <> Mid(x, m + 1 - i, 1) Then
huiwen = False
Exit Function
End If
Next i
huiwen = True
End Function
Function shengxu(x)
a = x \ 100
b = (x \ 10) Mod 10
c = x Mod 10
If a <= b And b <= c Then
shengxu = True
Else
shengxu = False
End If
End Function
Private Sub Command1_Click()
Dim a(20)
For i = 1 To 20
a(i) = 100 + Int(Rnd * 900)
Next i
Print "升序数如下"
For i = 1 To 20
If shengxu(a(i)) Then Print a(i);
Next i
Print "回文数如下"
For i = 1 To 20
If huiwen(a(i)) Then Print a(i);
Next i
End Sub
Public Function fun(ByVal n As Integer) As Integer
Dim res As Integer
res = 0
If n = StrReverse(n) Then
res = 1
End If
If (n \ 100) > ((n \ 10) Mod 10) And ((n \ 10) Mod 10) > (n Mod 10) Then
res = 2
End If
Return res
End Function
该函数用来判断是否为回文数或者升序数,如果是回文数,则返回值是1,如果是升序数,则返回值是2,其他返回值是0.