这道VB题是编程求出所有水仙花数,并在窗体显示。
PrivateSubcommand1_click()DimiAsInteger,aAsInteger,bAsIntegerDimcAsInteger,stAsString...
Private Sub command1_click()
Dim i As Integer, a As Integer, b As Integer
Dim c As Integer, st As String
For i = 100 To 999
a = i \ 100
b = (i Mod 100) \ 10
c = i Mod 10
If i = a ^ 3 + b ^ 3 + c ^ 3 Then
st = i & " = " & a & "^3 + " & b & "^3 +" & c & "^3"
List1.AddItem st
End If
Next i
End Sub
所谓水仙花数,是指一个三位数,其个位数字的立方和等于该数本身。如153=1^3+5^3+3^3,程序界面自己设定。我做的时候出现错实时错误“424”,请高手指出错误的地方告诉我,谢谢。 展开
Dim i As Integer, a As Integer, b As Integer
Dim c As Integer, st As String
For i = 100 To 999
a = i \ 100
b = (i Mod 100) \ 10
c = i Mod 10
If i = a ^ 3 + b ^ 3 + c ^ 3 Then
st = i & " = " & a & "^3 + " & b & "^3 +" & c & "^3"
List1.AddItem st
End If
Next i
End Sub
所谓水仙花数,是指一个三位数,其个位数字的立方和等于该数本身。如153=1^3+5^3+3^3,程序界面自己设定。我做的时候出现错实时错误“424”,请高手指出错误的地方告诉我,谢谢。 展开
推荐律师服务:
若未解决您的问题,请您详细描述您的问题,通过百度律临进行免费专业咨询