寻找回文数 20
寻找并输出11~999之间的数m它满足m的,m的平方,m的立方均为回文数。回文数就是左右对称的整数,例如,121,94249等。满足上述条件的数如11,它的平方数121,...
寻找并输出11~999之间的数m它满足m的,m的平方,m的立方均为回文数。回文数就是左右对称的整数,例如,121,94249等。满足上述条件的数如11,它的平方数121,立方1331,都是回文数。要求编制函数int svalue
(long m)实现此功能,如果数 回文数则返回1,反之返回0.在主函数中将三重回文数输出。
哪位高人指点一下啊,谢谢了! 展开
(long m)实现此功能,如果数 回文数则返回1,反之返回0.在主函数中将三重回文数输出。
哪位高人指点一下啊,谢谢了! 展开
2个回答
展开全部
Option Explicit
Private Sub Command1_Click()
Dim a(0 To 9) As Integer, i As Long, flg As Boolean
Dim l As Long, j As Integer, sum As Integer
For i = 10 To 1000
l = i * i
Erase a
Call sub1((l), a, flg)
If flg Then
For j = 0 To 9
sum = sum + a(j)
Next j
If sum = 2 Then
List1.AddItem CStr(i) & "^2="并销 & Str(l)
End If
End If
sum = 0
Next i
End Sub
Private Sub sub1(x As Long, a() As Integer, bl As Boolean)
Dim n As Integer, idx As Integer, i As Integer
bl = False
n = Len(CStr(x))
For i = 1 To n / 2
If Mid(CStr(x), i, 1) <> Mid(CStr(x), n - i + 1, 1) Then
Exit Sub
End If
Next i
bl = True
For i = 1 To n
idx = x Mod 10
a(idx) = 1
x = (x \ 10)
Next i
End Sub
祝旁洞你绝启游好运!
Private Sub Command1_Click()
Dim a(0 To 9) As Integer, i As Long, flg As Boolean
Dim l As Long, j As Integer, sum As Integer
For i = 10 To 1000
l = i * i
Erase a
Call sub1((l), a, flg)
If flg Then
For j = 0 To 9
sum = sum + a(j)
Next j
If sum = 2 Then
List1.AddItem CStr(i) & "^2="并销 & Str(l)
End If
End If
sum = 0
Next i
End Sub
Private Sub sub1(x As Long, a() As Integer, bl As Boolean)
Dim n As Integer, idx As Integer, i As Integer
bl = False
n = Len(CStr(x))
For i = 1 To n / 2
If Mid(CStr(x), i, 1) <> Mid(CStr(x), n - i + 1, 1) Then
Exit Sub
End If
Next i
bl = True
For i = 1 To n
idx = x Mod 10
a(idx) = 1
x = (x \ 10)
Next i
End Sub
祝旁洞你绝启游好运!
推荐律师服务:
若未解决您的问题,请您详细描述您的问题,通过百度律临进行免费专业咨询