Results 1 to 4 of 4

Thread: Try to solve Fibonacci Sequence in common way.

  1. #1
    Junior Member
    Join Date
    May 2007
    Location
    Thailand
    Posts
    1


    Post

    As you may know (or not), that the easiest way to find the Nth
    number of the Fibonacci Sequence is to use recursive function

    It looks like this


    [code]
    #include <stdio.h>

    long fib(int num) {
    [SIZE=2]ใครช่างใจร้ายใจดำ ทำกับฉันได้ !!![/SIZE]

  2. #2


    Recursion often has other benefits that can make up for lost performance. In particular, the readability and elegance of the code, and maintainability.

    If the body of the function is heavy, then the function-call overhead can quickly become insignificant. If the function body is small and light, as in your Fibonacci example, then the overhead for the recursive calls can be significant in comparison.

  3. #3
    Junior Member
    Join Date
    Dec 2008
    Location
    Bangkok
    Posts
    6


    hmm.....

    i thought that there would be a little bug in case

    " num = 0 " & "num less than 0"

    so, i suggests that it would be

    " if(num<2)return num; " hence, the error gonna be debuged.

    ^^
    Moore's law = ความขี้เกียดเพิ่มขึ้นเป็น 2 เท่าทุก 18 เดือน T.T

  4. #4
    Senior Member retool2's Avatar
    Join Date
    Aug 2008
    Location
    Under Relocation
    Posts
    178


    infinity loop
    long fib(int num) {
    if(num==1) return 1;
    else {
    return fib(num-1) + fib(num-2);
    }
    }[/b]
    if num=2
    then return fib(1)+fib(0)
    after that fib(0) cause [b]fib(-1) and fib(-2)[b]
    and so on...

Similar Threads

  1. Botnet Used To Solve CAPTCHA And Snatch Up Premium Tickets
    By newsbot in forum World Hacking/Security News
    Replies: 0
    Last Post: 07-03-2010, 04:01 AM
  2. Replies: 0
    Last Post: 30-09-2008, 01:55 PM
  3. create and solve perfect maze
    By retool2 in forum PHP,ASP,Javascript, Html
    Replies: 0
    Last Post: 25-09-2008, 03:32 PM
  4. Replies: 0
    Last Post: 20-01-2004, 07:53 PM
  5. Replies: 1
    Last Post: 18-11-2003, 08:23 PM

Members who have read this thread : 0

Actions : (View-Readers)

There are no names to display.

Posting Permissions

  • You may not post new threads
  • You may not post replies
  • You may not post attachments
  • You may not edit your posts
  •  
Who's Online (0)
0
0