Created
June 20, 2020 09:33
Fibonacci Number
This file contains 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