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 Longn = 1b = a / 10While b >= 1n = n + 1b = a / (10
来源:学生作业帮助网 编辑:作业帮 时间:2024/11/15 18:22:02
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 Longn = 1b = a / 10While b >= 1n = n + 1b = a / (10
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
为什么不对呢?
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 Longn = 1b = a / 10While b >= 1n = n + 1b = a / (10
对的.仅仅有点小问题.
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 Sub