用vb求出[2000,9999]以内的所有回文数的个数。

请高手们帮帮忙!本人将不胜感激!
2025-01-04 01:16:15
推荐回答(4个)
回答1:

所谓回文数是从左至右与从右至左读起来都是一样的数字,如:121是一个
'回文数。编写程序,求在500-900的范围内所有能被3整除的回文数的个数。

Private Sub Form_Click()
Dim i, j, k, z As Integer
For i = 5 To 8
For j = 0 To 9
z = i * 100 + j * 10 + i
If z Mod 3 = 0 Then
Print z
k = k + 1
End If
Next
Next
Print k

End Sub

这是前几天有个人提问,我回答的,你自己研究改一下吧,还可以优化一下。

回答2:

楼上那个方法简单,下面是个笨方法:
Dim a As Integer, b As Integer, c As Integer, d As Integer, n As Integer
Private Sub Form_click()
For a = 2 To 9
For b = 0 To 9
For c = 0 To 9
For d = 0 To 9
If a * 10 + b = d * 10 + c Then
n = n + 1
End If
Next d
Next c
Next b
Next a
Print "回文数的个数:" & n
End Sub

回答3:

http://baike.baidu.com/view/101387.htm

回答4:

Private Sub Command1_Click()
For i = 2000 To 9999
If Trim(Str(i)) = Trim(StrReverse(Str(i))) Then
Print Str(i)
End If
Next
End Sub