VB:用调用函数的方法找出所有三位数的水仙花数.
题目
VB:用调用函数的方法找出所有三位数的水仙花数.
这是我写的代码:
Private Sub Command1_Click()
Dim a(101,999) As Integer
For a = 101 To 999 Step 1
If isnum = True Then Print a;
Next
End If
End Sub
Private Function isnum(n As Integer) As Boolean
a As Integer,b As Integer,c As Integer
a = n 100
b = n 10 Mod 10
c = n Mod 10
If n = a ^ 3 + b ^ 3 + c ^ 3 Then
isnum = True
Else
isnum = False
End If
End Function
运行时说我类型不匹配.
哪个类型啊?
帮我解决掉的加分.
答案
Private Sub Command1_Click()
Dim a As Integer
For a = 101 To 999 Step 1
If isnum(a) = True Then Print a;
Next
End Sub
Private Function isnum(n As Integer) As Boolean
Dim a As Integer, b As Integer, c As Integer
a = n 100
b = (n - a * 100) 10
c = n - a * 100 - b * 10
If n = a ^ 3 + b ^ 3 + c ^ 3 Then
isnum = True
Else
isnum = False
End If
End Function
举一反三
我想写一篇关于奥巴马的演讲的文章,写哪一篇好呢?为什么好
最新试题
热门考点