mirror of
https://github.com/kmc7468/cs420.git
synced 2025-12-15 06:58:50 +00:00
37 lines
669 B
C
37 lines
669 B
C
int fibonacci_loop(int n, int nonce) {
|
|
int result = 0;
|
|
|
|
for (int step = 0; step < 10; ++step) {
|
|
int x = nonce;
|
|
int y = nonce;
|
|
|
|
for (int i = 1; i < n; ++i) {
|
|
int newy = x + y;
|
|
newy += (x + y);
|
|
newy += (x + y);
|
|
newy += (x + y);
|
|
newy += (x + y);
|
|
newy += (x + y);
|
|
newy -= (x + y);
|
|
newy -= (x + y);
|
|
newy -= (x + y);
|
|
newy -= (x + y);
|
|
newy -= (x + y);
|
|
x = y;
|
|
y = newy;
|
|
}
|
|
|
|
result += y;
|
|
}
|
|
|
|
return result;
|
|
}
|
|
|
|
int fibonacci_recursive(int n, int nonce) {
|
|
if (n < 2) {
|
|
return nonce;
|
|
}
|
|
|
|
return fibonacci_recursive(n - 1, nonce) + fibonacci_recursive(n - 2, nonce);
|
|
}
|