Meta Interview Question

In sudo-code write a program that takes an integer called N and prints out the Fibonacci sequence to the Nth digit.

Interview Answers

Anonymous

May 6, 2009

First I'd clarify the exact definition of the sequence (whether you consider the first number to be 0 or 1). You may need to adjust N by 1 before calling the program. int Fib(int N) { int prevprev = 0; int prev = 1; for (int i = 0; i < N; i++) {print prevprev; int cur = prevprev + prev; prevprev = prev; prev = cur; }}

2

Anonymous

Jul 13, 2011

@Anon: The question was about printing it till 'Nth digit', not n times.