朋友编程中,碰到这样一个问题,我不知应不应贴在这里,大家有会的,还请多多帮忙:、
   求助 写出通项式来表达:
  
   2/1+3/2-5/3+8/5-13/8+21/13-34/21…………
大家找出规律了吗?怎样写呢?

解决方案 »

  1.   

    分子,分母:
    2+3=5,3+5=8,5+8=13,8+13=21,13+21=34
    1,-1,1,-1dim j
    dim iLoop as long
    dim x1,x2,y1,y2
    dim k
    dim temp
    k=-1
    x1=2
    x2=3
    y1=1
    y2=2
    j=x1/y1+x2/y2
    for iloop=3 to 1000
    k=k*(-1)
    x1=x1+x2
    temp=x1
    x1=x2
    x2=tempy1=y1+y2
    temp=y1
    y1=y2
    y2=tempj=j+k*x2/y2next
      

  2.   

    Dim j
    Dim s As String
    Dim iLoop As Long
    Dim x1, x2, y1, y2
    Dim k
    Dim temp
    k = 1x1 = 2
    x2 = 3
    y1 = 1
    y2 = 2
    j = 2 / 1 + 3 / 2For iLoop = 3 To 10
    k = k * (-1)
    x1 = x1 + x2
    temp = x1
    x1 = x2
    x2 = tempy1 = y1 + y2
    temp = y1
    y1 = y2
    y2 = tempj = j + k * x2 / y2
    NextEnd Sub
      

  3.   

    Private Sub Command1_Click()
        Dim dblSum As Double
        Dim lngSon As Long
        Dim lngParent As Long
        Dim boolTemp As Boolean
        Dim lngLastSon As Long
        Dim lngLastParent As Long
        
        Dim i As Long
        
        i = 0
        
        lngSon = 2
        lngParent = 1
        
        dblSum = lngSon / lngParent
        
        boolTemp = False
        
        lngLastSon = lngSon
        lngLastParent = lngParent
        
        Do
            
            boolTemp = Not boolTemp
            
            lngParent = lngLastSon
            lngSon = lngLastSon + lngLastParent
            
            If boolTemp = True Then
                dblSum = dblSum + (lngSon / lngSon)
            Else
                dblSum = dblSum - (lngSon / lngSon)
            End If
            
            lngLastSon = lngSon
            lngLastParent = lngParent
            
            i = i + 1
            
            If i > 10 Then
                Exit Do
            End If
        Loop
        
        Debug.Print dblSum
    End Sub
      

  4.   

    i1=2
    j1=1
    i2=3
    j2=2
    r=i1/j1+i2/j2
    n=1
    do until n=X
      i1=i1+i2
      i2=i1+i2
      j1=j1+j2
      j2=j1+j2
      r=r-(i1/j1+i2/j2)
      n=n+1
    loop
    msgbox r我猜想你的公式的第一个数前面是负号的,这样才有规律,这样的话代码就是:
    i1=2
    j1=1
    i2=3
    j2=2
    r=0
    n=0
    do until n=X
      r=r-(i1/j1+i2/j2)
      i1=i1+i2
      i2=i1+i2
      j1=j1+j2
      j2=j1+j2
      n=n+1
    loop
    msgbox r
      

  5.   

    蓝天兄弟过多地使用临时变量temp来计算后面的数了。
    我的公式中,只有
      i1=i1+i2
      i2=i1+i2
      j1=j1+j2
      j2=j1+j2
    想一下,是不是达到i1是前面两个的和?i2又是前面两个的和?