'在去掉前导R的空格后,
'检查R是否闭敏陪和StrReverse(R),相等,
'算法如下:
N=12345
R=trim(str(N))
if R=StrReverse(R) then
print "是回文数"
else
拿粗 print "不轿蠢是回文数"
end if
新建工程,一个文本散李框,输入你需要判断的数字,一个按钮,输入如下代码:
Private Sub Command1_Click()Dim i As Long
For i = 1 To Len(Text1.Text) \ 2
冲简迟 If Mid(Text1.Text, i, 1) <> Mid(Text1.Text, Len(Text1.Text) + 1 - i, 1) Then Exit For
Next i
If i > Len(Text1.Text) \ 2 Then
咐旅MsgBox Text1.Text & "是回文数!"
Else
MsgBox Text1.Text & "不是回文数!"
End If
End Sub
欢迎分享,转载请注明来源:内存溢出
评论列表(0条)