关于一个算法的问题
1、 勾股定理中三个数的关系:a^2+b^2=c^2。编写程序,输出100以内的满足以上关系的数的组合,列如3,4,5就是一个整数的组合。
在哪里找突破口啊?
[解决办法]
Private Sub Command2_Click()
Dim i As Integer
Dim j As Integer
Dim dblTemp As Double
Dim k As Integer
For i = 1 To 100
For j = i To 100
dbl = i ^ 2 + j ^ 2
dblTemp = Sqr(dbl)
If dblTemp = Int(dblTemp) Then
If i + j > dblTemp And j - i < dblTemp And dblTemp <= 100 Then
Debug.Print i & ": " & j & ": " & dblTemp
End If
End If
Next
Next
End Sub
[解决办法]
'上面漏写了一个定义
Private Sub Command2_Click()
Dim i As Integer
Dim j As Integer
Dim dbl As Double
Dim dblTemp As Double
Dim k As Integer
For i = 1 To 100
For j = i To 100
dbl = i ^ 2 + j ^ 2
dblTemp = Sqr(dbl)
If dblTemp = Int(dblTemp) Then
If i + j > dblTemp And j - i < dblTemp And dblTemp <= 100 Then
Debug.Print i & ": " & j & ": " & dblTemp
End If
End If
Next
Next
End Sub