Files
cs420/examples/fib4.c
Jeehoon Kang b929dc334d Initial commit
2020-03-17 17:31:16 +09:00

23 lines
299 B
C

int fibonacci(int n) {
int i = 0;
int t1 = 0, t2 = 1, next_term = 0;
if (n < 2) {
return n;
}
i = 1;
while (i < n) {
next_term = t1 + t2;
t1 = t2;
t2 = next_term;
++i;
}
return t2;
}
int main() {
return fibonacci(9);
}