题目为:
1.  勾股定理中3个数的关系是:a^2+b^2=c^2.编写程序,输出30以内满足上述关系的整数组合.
    例如:3,4,5 是一个整数组合.2.  编写程序,打印如下所示的"数字金字塔":
                 
                 1
               1 2 1  
             1 2 3 2 1
           1 2 3 4 3 2 1 
         1 2 3 4 5 4 3 2 1
       1 2 3 4 5 6 5 4 3 2 1
     1 2 3 4 5 6 7 6 5 4 3 2 1
   1 2 3 4 5 6 7 8 7 6 5 4 3 2 1 
 1 2 3 4 5 6 7 8 9 8 7 6 5 4 3 2 1    求高手悉心指导,不胜感激..........

解决方案 »

  1.   

    var i,j:integer;
        k:real;
    begin
      for i:=1 to 30 do
        for j:=1 to 30 do
        begin
          k:=power(i*i+j*j,0.5);
          if (trunc(k)=k) and (k<=30) then
              memo1.Lines.Add(format('%d,%d,%f',[i,j,k]))
       end;
    end;
      

  2.   

    第一题不太难.第二题太长不去想了
    1.
    Dim i As Long, j As Long, m As Long
    Cls
    For i = 1 To 30
        For j = i To 29
            For m = j To 28
                If i ^ 2 + j ^ 2 = m ^ 2 Then Print i, j, m
            Next
        Next
    Next
      

  3.   

    dim result as integer
    dim i, j as integerfor i = 1 to 30
       for j = 1 to 30
           result = sqr(i * i + j * j)
           if (result * result) = (i * i + j * j) then 
               me.print i:",":j:",":result
           end if
       next j
    next i
      

  4.   

    给100分
    不过,jinjazz(近身剪(充电中...)师兄,你好象用的不是vb的语法吧?
    本人用的是vb 6.0 ,请高手再次赐教`~~谢谢`~~
      

  5.   

    dim i , j as integer
    dim xStr as stringfor i = 1 to 9
        xstr = ""
        for j = 1 to 9 - i
            xstr = xstr & " "
        next j
        for j = i to 2 step -1
            xstr = xstr & cstr(j)
        next j
        xstr = xstr & "1"
        for j = 2 to i
           xstr = xstr & cstr(i)
        next j
        me.print xstr
    next i
      

  6.   

    第二题,从结构上讲可以写得更简单,只是这个显示是个问题,它又不是dos下,屏幕是80*25的
    所以要显示好,的确有点难度,关键还是显示在什么地方?
      

  7.   

    不要重复,其实很简单,循环体这样修改一下就可以了
    for i = 1 to 30
        for j = i + 1 to 30
            ........
        next j
    next i
      

  8.   

    1、
    Private Sub Command1_Click()
    Dim Result(100) As StringDim i As Integer
    Dim j As Integer
    Dim k As IntegerDim n As Integer
    n = 0
    For i = 1 To 30
       For j = i To 30
           For k = j To 30
               If i * i + j * j = k * k Then
                  Result(n) = i & "," & j & "," & k
                  n = n + 1
               End If
           Next
       Next
    Next
    End Sub2、
    Private Sub Command1_Click()
    Dim Result(10) As String
    Dim i As Integer
    Dim j As IntegerFor i = 1 To 9
       Result(i - 1) = String(2 * (9 - i), " ")
       For j = 1 To i
           Result(i - 1) = Result(i - 1) & " " & j
       Next j
       For j = i - 1 To 1 Step -1
           Result(i - 1) = Result(i - 1) & " " & j
       Next
    Next iEnd Sub
      

  9.   

    作业题?1
    Dim i As Integer, j As Integer, k As Integer, n As IntegerFor i = 1 To 30
        For j = i To 30
            n = i * i + j * j
            For k = 1 To 30
                If n = k * k Then Debug.Print i, j, k
            Next k
        Next j
    Next i
      

  10.   

    不要问了,肯定是作业题目第一题,随便找本VB的书上都会有个算法介绍的,自己不能去找找吗??
    第二题:www.google.com想好你的关键字
      

  11.   

    Private Sub Command1_Click()
    Dim a As Integer
    Dim b As Integer
    Dim c As IntegerFor a = 1 To 30
       For b = 1 To 30
          c = Sqr(a ^ 2 + b ^ 2)
          If c <= 30 Then
          If c ^ 2 = a ^ 2 + b ^ 2 Then Debug.Print "a=" & a & "  b=" & b & "  c=" & c
          End If
       Next b
    Next a
    End Sub
    -----------------------------
    a=3  b=4  c=5
    a=4  b=3  c=5
    a=5  b=12  c=13
    a=6  b=8  c=10
    a=7  b=24  c=25
    a=8  b=6  c=10
    a=8  b=15  c=17
    a=9  b=12  c=15
    a=10  b=24  c=26
    a=12  b=5  c=13
    a=12  b=9  c=15
    a=12  b=16  c=20
    a=15  b=8  c=17
    a=15  b=20  c=25
    a=16  b=12  c=20
    a=18  b=24  c=30
    a=20  b=15  c=25
    a=20  b=21  c=29
    a=21  b=20  c=29
    a=24  b=7  c=25
    a=24  b=10  c=26
    a=24  b=18  c=30
      

  12.   

    2.三角形
    Private Sub Command1_Click()
        stmp = ""
        For i = 1 To 9
            For j = 9 To -9 Step -1
                If Abs(j) < i + 1 And j <> 0 And j <> -1 Then
                    stmp = stmp & i + 1 - Abs(j)
                ElseIf j <> 0 And j <> -1 Then
                    stmp = stmp & "  "
                End If
            Next
            stmp = stmp & vbCrLf
        Next
        Me.Print stmp
    End Sub
      

  13.   

    输出结果:
     5             12            13 
     6             8             10 
     7             24            25 
     8             15            17 
     9             12            15 
     10            24            26 
     12            16            20 
     15            20            25 
     18            24            30 
     20            21            29 第二题:
    Dim i As Integer, j As Integer, str1 As StringFor i = 1 To 9
    str1 = String(9 - i, " ")
        For j = 1 To i
            str1 = str1 & j
        Next j
        For j = i - 1 To 1 Step -1
            str1 = str1 & j
        Next j
        Debug.Print str1
    Next i
      

  14.   

    第一题的效率还可以提高:
    Dim i As Integer, j As Integer, k As Integer, n As IntegerFor i = 1 To 30
        For j = i To 30
            n = i * i + j * j
            For k = j + 1 To 30
                If n = k * k Then Debug.Print i, j, k
            Next k
        Next j
    Next i
      

  15.   

    Private Sub Command2_Click()
    Dim i As Integer, j As Integer, str As String
    For i = 1 To 9
    str = String(9 - i, " ")
        For j = 1 To i
            str = str & j
        Next j
        For j = i - 1 To 1 Step -1
            str = str & j
        Next j
        Debug.Print str
    Next i
    End Sub
      

  16.   

    使用 i * i 的方式可能比 i^2 以及 sqr() 更快:Dim i As Integer, j As Integer, k As Integer, n As Integer
    Dim a As Integer, tt As Double
    tt = Timer
    For a = 1 To 1000
    For i = 1 To 30
        For j = i To 30
            n = i * i + j * j
            For k = j + 1 To 30
                If n = k * k Then Debug.Print "a=" & i & "  b=" & j & "  c=" & k
            Next k
        Next j
    Next i
    Next a
    Debug.Print Timer - tt 3.02109375000146
    Dim b As Integer
    Dim c As Integer
    Dim i As Integer, tt As Doublett = Timer
    For i = 1 To 1000
    For a = 1 To 30
       For b = 1 To 30
          c = Sqr(a ^ 2 + b ^ 2)
          If c <= 30 Then
          If c ^ 2 = a ^ 2 + b ^ 2 Then Debug.Print "a=" & a & "  b=" & b & "  c=" & c
          End If
       Next b
    Next a
    Next i
    Debug.Print Timer - tt 7.02937499999825 
     
      

  17.   

    差别没有那么大,后例的循环有问题,输出重复。更改
    ......
    For a = 1 To 30
       For b = a To 30
    ...... 4.27906249999796
      

  18.   

    2.
    Private Sub Command1_Click()
    Dim i As Integer, J As Integer, k As Integer, s(16) As String
    For i = 1 To 9
    For J = 0 To 16
    k = i - Abs(8 - J)
    s(J) = IIf(k > 0, k, " ")
    Next
    Me.Print Join(s, " ")
    Next
    End Sub
      

  19.   

    sigh!
    不就迟点看到贴子吗?连插嘴的份都没有了!
      

  20.   

    1
                   1 2 1  
                 1 2 3 2 1
               1 2 3 4 3 2 1 
             1 2 3 4 5 4 3 2 1
           1 2 3 4 5 6 5 4 3 2 1
         1 2 3 4 5 6 7 6 5 4 3 2 1
       1 2 3 4 5 6 7 8 7 6 5 4 3 2 1 
     1 2 3 4 5 6 7 8 9 8 7 6 5 4 3 2 1 想问一下,如果数字中间有空格的话,那么是否应该用tab()函数来实现呢?