我试图编写Pythagorean三元组,但我不知道为什么添加到列表框不起作用。
Private Sub BtnCom_Click(sender As Object, e As EventArgs) Handles BtnCom.Click
Dim A, B, C As Integer
Dim num As Integer = 1
Dim result As Integer
C = hypotenuse(A, B)
For A = 1 To 100
For B = 1 To 100
If (A ^ 2) + (B ^ 2) = (C ^ 2) And A < B Then
num = num + 1
result = num & "." & A & B & C & vbCr
ListBox1.Items.Add(result)
End If
Next
Next
End Sub
Function hypotenuse(A, B)
Dim c2, c3 As Single
c2 = (A ^ 2) + (B ^ 2)
c3 = Math.Sqrt(c2)
Return c3
End Function