VB 数列的前三位是123,以后一项为前三项之和,求25位到三十位之和

1个回答

  • Private Sub Command1_Click()

    Dim a As String, b As String, c, x As Long, sum As Long, sum1 As Long

    a = "1 2 3"

    b = a

    For i = 1 To 27

    c = Split(b)

    For j = 0 To UBound(c)

    x = x + c(j)

    Next

    a = a & " " & x

    b = Mid(b, InStr(b, " ") + 1) & " " & x

    If i >= 22 Then sum = sum + x

    x = 0

    Next

    Debug.Print a

    Debug.Print sum '25项至30项之和

    a = Replace(a, " ", "")

    Debug.Print a

    For i = 25 To 30

    sum1 = sum1 + Mid(a, i, 1)

    Next

    Debug.Print sum1 '25位到30位之和

    End Su