Domanda di colloquio di Meta

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

Risposte di colloquio

Anonimo

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

Anonimo

13 lug 2011

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