29 lines
326 B
Plaintext
29 lines
326 B
Plaintext
main() {
|
|
i = 0;
|
|
while i < 10 {
|
|
print fib_rec(i);
|
|
print fib_iter(i);
|
|
i = i + 1;
|
|
}
|
|
}
|
|
|
|
fib_rec(n) {
|
|
if n < 2 {
|
|
return 1;
|
|
}
|
|
return fib_rec(n - 1) + fib_rec(n - 2);
|
|
}
|
|
|
|
fib_iter(n) {
|
|
x0 = 1;
|
|
x1 = 1;
|
|
i = 0;
|
|
while i < n {
|
|
t = x0 + x1;
|
|
x0 = x1;
|
|
x1 = t;
|
|
i = i + 1;
|
|
}
|
|
return x0;
|
|
}
|