MathWorks Interview Question

Describe how you would code a Fibonacci series (not actually unexpected, pretty standard)

Interview Answers

Anonymous

Apr 3, 2013

The trick is to ask how many terms you need; the series is recursive so you need to show that you realize that certain ways of doing it will eat huge amounts of processor power.

Anonymous

Mar 15, 2016

cout> n; int firstterm = 0, secondterm = 1; cout << firstterm << "," << secondterm << ","; int nextterm = firstterm + secondterm; for(int i = 1; i < n - 1; i++) { cout << nextterm << ","; firstterm = secondterm; secondterm = nextterm; nextterm = firstterm + secondterm; }