Results 1 to 5 of 5

Thread: Urgent! For Next loop for Fibonacci numbers!!

  1. #1

    Thread Starter
    Junior Member
    Join Date
    Nov 1999
    Location
    Baytown, TX United States
    Posts
    19

    Post

    I need a For Next loop that will print the first 10 Fibonacci numbers 1,1,2,3,5,8,13,21,34,55)

  2. #2
    Lively Member
    Join Date
    Jun 1999
    Posts
    120

    Post

    this would entail a writing a function calling itself (recursive)

    sub main()
    dim ctr,i,j,k as integer

    i = 0
    j = 1
    k = 1

    fibGen(i,j,k)

    End

    sub fibGen(i,j,k as integer)

    do
    k = i + j
    i = j
    j = k
    ctr = ctr + 1
    msgbox(k)
    loop while (ctr < 10)

    end


    hope this would be of help...

  3. #3
    Lively Member
    Join Date
    Jun 1999
    Posts
    120

    Post

    ops....

    missing line...

    ...
    ctr = ctr + 1
    msgbox(k)
    /* this is the missing line */
    fibGen(i,j,k)
    loop while (ctr < 10)


  4. #4
    Guest

    Post

    I think this should help you
    if for some reason it doesn't work at least the F function has the correct algorithm to get what you need.

    public sub main()
    dim iC,iD as integer
    ic=inputbox("Enter the term number you want to get the value of...")
    iD=F(iC)
    msgbox iD
    end sub
    private function F(n as integer) as integer
    if n=1 or n=2 then
    F=1
    else
    F=F(n-1) + F(n-2)
    end if
    end function

  5. #5

    Thread Starter
    Junior Member
    Join Date
    Nov 1999
    Location
    Baytown, TX United States
    Posts
    19

    Post

    Thanks a bunch! It worked without the fibGen(i,j,k)

    ------------------
    kazooie21

Posting Permissions

  • You may not post new threads
  • You may not post replies
  • You may not post attachments
  • You may not edit your posts
  •  



Click Here to Expand Forum to Full Width