Question

Write an algorithm to return the fibonacci number. Show the trace of you algorithm for fib(6)....

Write an algorithm to return the fibonacci number. Show the trace of you algorithm for fib(6).

  1. when n <= 2 fib(n) = 1
  2. when n > 2 fib(n) = fib(n-1) + fib(n-2)
0 0
Add a comment Improve this question Transcribed image text
Answer #1

algorithm:

step1: set f1=1
setp2: set f2=1
step3: for i=1 to n-2
set temp=f1+f2
set f1=f2
   set f2=temp
step4:display f2 for nth fibonacci number
  

fib(6)::::

---->f1=1,f2=1

(1)---> temp=1+1=2

f1=1,f2=2

(2)-->temp=1+2=3 f1=2 f2=3

(3)-->temp=3+2=5 f1=3 f2=5

(4)--->temp=5+3=8 f1=5 f2=8

display f2 means "8"

fibonacii series

1 1 2 3 5 8 13 21 34 ----------

index;1 2 3 4 5 6 7 8

therefore 6th fibonacii is 8

Add a comment
Know the answer?
Add Answer to:
Write an algorithm to return the fibonacci number. Show the trace of you algorithm for fib(6)....
Your Answer:

Post as a guest

Your Name:

What's your source?

Earn Coins

Coins can be redeemed for fabulous gifts.

Not the answer you're looking for? Ask your own homework help question. Our experts will answer your question WITHIN MINUTES for Free.
Similar Homework Help Questions
ADVERTISEMENT
Free Homework Help App
Download From Google Play
Scan Your Homework
to Get Instant Free Answers
Need Online Homework Help?
Ask a Question
Get Answers For Free
Most questions answered within 3 hours.
ADVERTISEMENT
ADVERTISEMENT
ADVERTISEMENT