0

how the stack would look like for the following program if I give input as 5.

#include <stdio.h> int fibonacci(int number) { int retval; if (0 == number){ return 0; } if (1 == number){ return 1; } return(fibonacci(number-1) + fibonacci(number-2)); } int main() { int number = 0; int fibvalue = 1; while (1){ printf("please enter the number\n"); scanf("%d", &number); fibvalue = fibonacci(number); printf("computed fibonacci value %d\n", fibvalue); } return 1; } 

also give me links where i can learn about it

8
  • 8
    Shame on you for returning 1 from main. Commented Jun 10, 2010 at 17:01
  • 4
    If this is homework, please tag as such. Commented Jun 10, 2010 at 17:01
  • 2
    And is this a homework problem? Tag it appropriately if it is, and let us know some more specific questions you have. Commented Jun 10, 2010 at 17:01
  • 1
    At what point during execution do you want to know what the stack 'looks like', for example. Commented Jun 10, 2010 at 17:02
  • 3
    @Mark: Technically he doesn't; that return 1 is unreachable. :-) Commented Jun 10, 2010 at 17:13

1 Answer 1

1

Use a debugger, for example, GDB.

Shameless plug - take a look at my GDB intro presentation at New York City BSD User Group - there are plenty of examples of Fibonacci stack traces there.

Sign up to request clarification or add additional context in comments.

Comments

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.