设x,y都为整数,编程x^3+y^2=1000和x<=3的解和解数组,可用穷举法两重循环 急!!!在线等答案,谢谢
2个回答
展开全部
Option Explicit
Private Sub Form_Load()
Dim x As Long, y As Long
Dim arrOut() As String
Dim arrCount As Long
ReDim arrOut(0)
For x = 0 To 10
For y = 0 To 33
If x ^ 3 + y ^ 2 = 1000 Then
ReDim Preserve arrOut(arrCount)
arrOut(arrCount) = "x=" & x & " y=" & y
Debug.Print arrOut(arrCount)
arrCount = arrCount + 1
End If
Next
Next
Debug.Print UBound(arrOut)
End Sub
运行结束之后arrOut里面放的是结果
Private Sub Form_Load()
Dim x As Long, y As Long
Dim arrOut() As String
Dim arrCount As Long
ReDim arrOut(0)
For x = 0 To 10
For y = 0 To 33
If x ^ 3 + y ^ 2 = 1000 Then
ReDim Preserve arrOut(arrCount)
arrOut(arrCount) = "x=" & x & " y=" & y
Debug.Print arrOut(arrCount)
arrCount = arrCount + 1
End If
Next
Next
Debug.Print UBound(arrOut)
End Sub
运行结束之后arrOut里面放的是结果
追问
有没有可以代替arrout的简单点的代码啊?
追答
Option Explicit
Private Sub Form_Load()
Dim x As Long, y As Long
Dim Label1 As Label
Set Label1 = Controls.Add("VB.Label", "Label1")
Label1.Move 0, 0, Me.ScaleWidth, Me.ScaleHeight
Label1.Visible = True
Label1.Font.Size = 14
For x = 0 To 10
For y = 0 To 33
If x ^ 3 + y ^ 2 = 1000 Then
Label1.Caption = Label1.Caption & "x=" & x & " y=" & y & vbCrLf
End If
Next
Next
End Sub
推荐律师服务:
若未解决您的问题,请您详细描述您的问题,通过百度律临进行免费专业咨询