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

boxerxp2022-10-04 11:39:541条回答

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
为什么不对呢?

已提交,审核后显示!提交回复

共1条回复
酷爱电影的人 共回答了15个问题 | 采纳率80%
对的.仅仅有点小问题.
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
1年前

相关推荐