Skip to content

Instantly share code, notes, and snippets.

@imshayne
Created June 20, 2020 09:33
Show Gist options
  • Save imshayne/a40007645a2235d8e4f9c783a2f4160f to your computer and use it in GitHub Desktop.
Save imshayne/a40007645a2235d8e4f9c783a2f4160f to your computer and use it in GitHub Desktop.
Fibonacci Number
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