Pregunta de entrevista de Meta

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

Respuestas de entrevistas

Anónimo

6 may 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

Anónimo

13 jul 2011

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