VB 代码 求水仙花数
PrivateSubCommand1_Click()DimiAsInteger,aAsInteger,bAsInteger,cAsInteger,stAsIntegerF...
Private Sub Command1_Click()
Dim i As Integer, a As Integer, b As Integer, c As Integer, st As Integer
For a = 1 To 9
For b = 0 To 9
For c = 0 To 9
i = a * 100 = b * 100 + c * 100
If i = a ^ 3 = b ^ 3 + c ^ 3 Then
st = i & "=" & a & " ^3 + " & b & " ^3 +" & c & "+3"
List1.AddItem st
End If
Next c
Next b
Next a
End Sub
这个代码中st = i & "=" & a & " ^3 + " & b & " ^3 +" & c & "+3"有什么错误? 展开
Dim i As Integer, a As Integer, b As Integer, c As Integer, st As Integer
For a = 1 To 9
For b = 0 To 9
For c = 0 To 9
i = a * 100 = b * 100 + c * 100
If i = a ^ 3 = b ^ 3 + c ^ 3 Then
st = i & "=" & a & " ^3 + " & b & " ^3 +" & c & "+3"
List1.AddItem st
End If
Next c
Next b
Next a
End Sub
这个代码中st = i & "=" & a & " ^3 + " & b & " ^3 +" & c & "+3"有什么错误? 展开
3个回答
展开全部
错的不是这条语句,而是其他的,而且错得离谱。下面是正确的:
Private Sub Command1_Click()
Dim i As Integer, a As Integer, b As Integer, c As Integer, st As String
For a = 1 To 9
For b = 0 To 9
For c = 0 To 9
i = a * 100 + b * 10 + c
If i = a ^ 3 + b ^ 3 + c ^ 3 Then
st = i & " = " & a & "^3 + " & b & "^3 + " & c & "^3"
List1.AddItem st
End If
Next c
Next b
Next a
End Sub
Private Sub Command1_Click()
Dim i As Integer, a As Integer, b As Integer, c As Integer, st As String
For a = 1 To 9
For b = 0 To 9
For c = 0 To 9
i = a * 100 + b * 10 + c
If i = a ^ 3 + b ^ 3 + c ^ 3 Then
st = i & " = " & a & "^3 + " & b & "^3 + " & c & "^3"
List1.AddItem st
End If
Next c
Next b
Next a
End Sub
追问
其实看到你的之后我发现原来我抄代码抄错了。哈。。谢谢
展开全部
Private Sub Command1_Click()
Dim i As Integer, a As Integer, b As Integer, c As Integer, st As String
For a = 1 To 9
For b = 0 To 9
For c = 0 To 9
i = a * 100 + b * 10 + c
If i = a ^ 3 + b ^ 3 + c ^ 3 Then
st = i & "=" & a & " ^3 + " & b & " ^3 +" & c & "^3"
List1.AddItem st
End If
Next c
Next b
Next a
End Sub
其实你的代码有点繁,这样即可:
Private Sub Command1_Click()
Dim I As Integer
For I = 100 To 999
If Val(Left(CStr(I), 1)) ^ 3 + Val(Mid(CStr(I), 2, 1)) ^ 3 + Val(Right(CStr(I), 1)) ^ 3 = I Then
List1.AddItem I
end if
Next I
End Sub
Dim i As Integer, a As Integer, b As Integer, c As Integer, st As String
For a = 1 To 9
For b = 0 To 9
For c = 0 To 9
i = a * 100 + b * 10 + c
If i = a ^ 3 + b ^ 3 + c ^ 3 Then
st = i & "=" & a & " ^3 + " & b & " ^3 +" & c & "^3"
List1.AddItem st
End If
Next c
Next b
Next a
End Sub
其实你的代码有点繁,这样即可:
Private Sub Command1_Click()
Dim I As Integer
For I = 100 To 999
If Val(Left(CStr(I), 1)) ^ 3 + Val(Mid(CStr(I), 2, 1)) ^ 3 + Val(Right(CStr(I), 1)) ^ 3 = I Then
List1.AddItem I
end if
Next I
End Sub
追问
看不懂。。。哈不过多谢了啊。。。
追答
!!
已赞过
已踩过<
评论
收起
你对这个回答的评价是?
展开全部
st应该定义为字符型 st as string 试试
已赞过
已踩过<
评论
收起
你对这个回答的评价是?
推荐律师服务:
若未解决您的问题,请您详细描述您的问题,通过百度律临进行免费专业咨询