fibanocci with one RECURSIVE CALL only

通常fibanocci要两个递归调用  复杂度o(2^n)

但是用指针的话,可以只用1次call   复杂度 o(n)

(10 minutes) Write a program called fib.c that calculates the nth fibanocci

number. The equation for the Fibonacci numbers is defined as follows:

Fib(0)=0

1.
Fib(N)=Fib(N−1)+Fib(N−2)

  1. Name your executable fib.out
  2. Your program should accept N as a command line argument
  3. You MUST solve this program RECURSIVELY
  4. Unlike the example in class, you may only have ONE RECURSIVE CALL in

    your function

    1. Hint pointers help make this possible.

  5. Here are the first 100 numbers in the Fibonacci sequence
  6. Examples

    1../fib.out 0
    The 0th fibanocci number is 0.

    2../fib.out 1
    The 1th fibanocci number is 1.

    3../fib.out 10
    The 10th fibanocci number is 55.

Leave a Reply

Your email address will not be published. Required fields are marked *