作业帮 > 综合 > 作业

vb 守型数 设A为一个整数,如果a^2=x*a,成立,则称a为 守型数,如5^2=25,25^=625,求1-1000

来源:学生作业帮 编辑:作业帮 分类:综合作业 时间:2024/11/06 01:43:49
vb 守型数 设A为一个整数,如果a^2=x*a,成立,则称a为 守型数,如5^2=25,25^=625,求1-1000守型数
Public Function fun1(a As Long)
Dim b As Single,c As Single,n As Integer,d As Long
n = 1
b = a / 10
While b >= 1
n = n + 1
b = a / (10 ^ n)
Wend
c = (a ^ 2 - a) / (10 ^ n)
If Fix(c) = c Then
d = a
End If
fun1 = d
End Function
调用时:
Private Sub Form_Click()
Dim a As Long
For a = 1 To 1000
r = fun1(a)
Print fun1(a);
Next a
End Sub
为什么不对呢?
对的.仅仅有点小问题.
Public Function fun1(a As Long)
Dim b As Single, c As Single, n As Integer, d As Long
n = 1
b = a / 10
While b >= 1
n = n + 1
b = a / (10 ^ n)
Wend
c = (a ^ 2 - a) / (10 ^ n)
If Fix(c) = c Then
d = a
End If
fun1 = d
End Function
'调用时:
Private Sub Form_Click()
Dim a As Long
For a = 1 To 1000
r = fun1(a)
If r = a Then Print fun1(a);
Next a
End Sub
Private Sub Form_Load()
Me.AutoRedraw = True
End Su