write a c++ program generat a fibonacci series using while loop statement .(Hint0,1,1,2,3,5,8,13,21,34,55,...)

3 Years
Discussion Span
Last Post by Banfa

Start with the values 0 and 1 each value in the series is made up by adding the previous 2 values so

0 + 1 = 1
1 + 1 = 2
1 + 2 = 3
2 + 3 = 5
3 + 5 = 8
5 + 8 = 13

Just write a loop that does that, should be easily done with 3 variables.

Then show us your work.


And when it comes to Fibonachi array, do you like recursion or not, would you accept aprosimation, or is it just like same old plain...


Potentially useless anecdote: When I was studying for my Bachelor's, I took a class called Programming Languages (later to be replaced by compilers). The subject of study was an obscure multi-paradigm language called Oz (with it's equally obscure IDE, Mozart).
For one of the last assignments, I had to write a Fibonacci function. Being that the Fibonacci series reuses its values, I wrote a function that stored values in a dictionary. Then, instead of a long painful O(n^2) wait, Fibonacci(500) was done in milli-(micro?)seconds.


That is one way although there is also a formula for the nth Fibonacci number

Where Phi = the golden ratio = 1.61803398874989484820458683436563811772030917980576

Fib(n) = (pow(Phi, n) - pow(-Phi, -n)) / sqrt(5)

This topic has been dead for over six months. Start a new discussion instead.
Have something to contribute to this discussion? Please be thoughtful, detailed and courteous, and be sure to adhere to our posting rules.