mirror of
https://github.com/kmc7468/cs420.git
synced 2025-12-15 23:18:48 +00:00
21 lines
337 B
C
21 lines
337 B
C
int fibonacci_loop(int n, int nonce) {
|
|
int x = nonce;
|
|
int y = nonce;
|
|
|
|
for (int i = 1; i < n; ++i) {
|
|
int newy = x + y;
|
|
x = y;
|
|
y = newy;
|
|
}
|
|
|
|
return y;
|
|
}
|
|
|
|
int fibonacci_recursive(int n, int nonce) {
|
|
if (n < 2) {
|
|
return nonce;
|
|
}
|
|
|
|
return fibonacci_recursive(n - 1, nonce) + fibonacci_recursive(n - 2, nonce);
|
|
}
|