This is a frequently asked programming interview question to print a fibonacci series of given length.
Wikipedia defines it very well.
The Fibonacci numbers are the numbers in the following integer sequence, called the Fibonacci sequence, and characterized by the fact that every number after the first two is the sum of the two preceding ones:
Often, especially in modern usage, the sequence is extended by one more initial term:
- We need to store numbers in variables. Since we need to store multiple variables of same type, instead of creating multiple variables, we can use an array or a collection class.
- In this post, I will use a collection class instead of arrays. In an interview if you solve a program using collections, it is really appreciated and leaves a positive impact on your interviewer.
- To find nth index number in fibonacci series, you need to access and add (n-1)th index and (n-2)th indexed element.
If you like my posts, please like, comment, share and subscribe.