Private Sub Command1_Click()
Dim i As Long, s As String, t As String
For i = 1 To 10000
For j = 1 To Len(CStr(i))
s = Mid(CStr(i), j, 1) & s
Next j
If i = CStr(i) Then
a = i * i
For k = 1 To Len(CStr(a))
t = Mid(CStr(a), k, 1) & t
Next k
End If
Next i
If t = CStr(a) Then b = i & "^" & "2" & "=" & a
List1.AddItem b
End Sub
哪里错了啊啊 啊??
累觉不爱00
编程找出10000以内所有的回文数的平方仍是回文数的数
答案:2 悬赏:50 手机版
解决时间 2021-03-18 06:18
- 提问者网友:伴风望海
- 2021-03-17 07:51
最佳答案
- 五星知识达人网友:逐風
- 2021-03-17 09:08
错得很多,一是s和t需要初始化为空,二是IF判断应该在循环里面,还有细节错误,而且判断回文应该定义为函数,我下面的程序调试通过的,你可以参考:
Private Sub Command1_Click()
Dim i As Long
For i = 1 To 10000
If chk_hui(i) Then
If chk_hui(i * i) Then MsgBox i
End If
Next i
End Sub
Private Function chk_hui(x) As Boolean
Dim i, s1, s2
s1 = x & ""
s2 = ""
For i = 1 To Len(s1)
s2 = Mid(s1, i, 1) & s2
Next i
chk_hui = s1 = s2
End Function
由于我没有List1,所以我只是把结果msgbox,你自行修改为你要的形式。
Private Sub Command1_Click()
Dim i As Long
For i = 1 To 10000
If chk_hui(i) Then
If chk_hui(i * i) Then MsgBox i
End If
Next i
End Sub
Private Function chk_hui(x) As Boolean
Dim i, s1, s2
s1 = x & ""
s2 = ""
For i = 1 To Len(s1)
s2 = Mid(s1, i, 1) & s2
Next i
chk_hui = s1 = s2
End Function
由于我没有List1,所以我只是把结果msgbox,你自行修改为你要的形式。
全部回答
- 1楼网友:罪歌
- 2021-03-17 09:38
我知道你也懂一点的,我列个思路:
for i=1 to 10000
{
a=i*i
j=0
while(a/10)
{b[j]=a/10;
a=a/10;
j++;
}
a[j]=a; //接收最后一个数
//判断是否回文数
for k=0 to j/2
if(b[k] <> b[j-k])
break;
if(k==j/2)
输出b数组;
}
我要举报
如以上回答内容为低俗、色情、不良、暴力、侵权、涉及违法等信息,可以点下面链接进行举报!
点此我要举报以上问答信息
大家都在看
推荐资讯