Created
June 20, 2020 09:33
-
-
Save imshayne/a40007645a2235d8e4f9c783a2f4160f to your computer and use it in GitHub Desktop.
Fibonacci Number
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
int fibo(int); | |
int fibo(int N) { | |
if (0 == N) return 0; | |
if (1 == N || 2 == N) return 1; | |
int pre = 1, cur = 1; | |
for (int i = 3; i <= N; ++i) { | |
int sum = pre + cur; | |
pre = cur; | |
cur = sum; | |
} | |
return cur; | |
} |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment