dim a as long ,b as long ,c as long for a = 1 to 30 
   for b = 1 to 30
      for c=1 to 30
         if  a*a+b*b=c*c then
              debug.print "a:" & a & "b:" & b & "c:" & c & vbcrlf
         end if
      next
   next
next

解决方案 »

  1.   

    Dim a As Long, b As Long, c As LongFor a = 1 To 30
       For b = 1 To 30
          c = CInt(Sqr(a * a + b * b))
          If c >= 1 And c <= 30 And a * a + b * b = c * c Then
            Debug.Print "a:" & a & " b:" & b & " c:" & c & vbCrLf
          End If
       Next
    Next
      

  2.   

    如果是整数,那么3以下都不可能组成三角形
    要组合,不要排列,那么i最大,m最小
    Private Sub Command1_Click()
        Dim i As Integer
        Dim j As Integer
        Dim m As Integer
        Dim sTmp As String
        List1.Clear    
        For i = 3 To 30
            For j = 3 To i
                For m = 3 To j
                    If m ^ 2 + j ^ 2 = i ^ 2 Then
                        sTmp = CStr(j) & "," & CStr(m) & "," & CStr(i)
                        List1.AddItem sTmp
                        Text1.Text = CStr(CInt(IIf(IsNumeric(Text1.Text), Text1.Text, 0)) + 1)
                    End If
                Next m
            Next j
        Next i
        
    End Sub
      

  3.   

    skywolfY(莫愁)已经将答案做的很完美,没什么改进空间了如果吹毛求疵的话,还可以将i,j,m的初始量改为5,4,3.(因为我们知道这分别是i,j,m的最小值):
    Option Explicit
    Private Sub Command1_Click()
    Dim i As Integer
    Dim j As Integer
    Dim m As Integer
        
    For i = 5 To 30
        For j = 4 To i
            For m = 3 To j
                If m * m + j * j = i * i Then Print m; j; i
            Next m
        Next j
    Next i
        
    End Sub不知道能不能从skywolfY身上蹭些小分
    : )
      

  4.   

    u can use addition instead of multiplication
      

  5.   

    as thisPrivate Sub Command8_Click()
        Dim i As Long
        Dim j As Long
        Dim k As Long
        Dim i2 As Long
        Dim j2 As Long
        Dim k2 As Long
        Dim n As Integer
        n = 30
        i2 = 0
        For i = 1 To n
            i2 = i2 + (i + i - 1) '这就是i*i和(i+1)*(i+1)的差别
            j2 = i2
            For j = i + 1 To n
                j2 = j2 + (j + j - 1) '这就是j*j和(j+1)*(j+1)的差别
                k2 = j2
                For k = j + 1 To i + j
                    k2 = k2 + (k + k - 1) '这就是k*k和(k+1)*(k+1)的差别
                    If (i2 + j2) = k2 Then
                        Debug.Print i, j, k
                    End If
                Next k
            Next j
        Next i
    End Subthe result
     3             4             5 
     5             12            13 
     6             8             10 
     7             24            25 
     8             15            17 
     9             12            15 
     10            24            26 
     12            16            20 
     15            20            25 
     16            30            34 
     18            24            30 
     20            21            29 
     21            28            35