Skip to content

Instantly share code, notes, and snippets.

@Nata01
Created December 15, 2015 13:07
Show Gist options
  • Save Nata01/b95ab865f22fc3954d17 to your computer and use it in GitHub Desktop.
Save Nata01/b95ab865f22fc3954d17 to your computer and use it in GitHub Desktop.
Fibonacci numbers. Simplest algorithm.
int fibSimple(int elem){
if(elem < 0){
return 0;
}
if(elem == 0){
return 0;
}
if(elem == 1){
return 1;
}
else{
int value;
int prev = 0;
int cur = 1;
for(int i = 2; i <= elem; i++){
value = prev + cur;
prev = cur;
cur = value;
}
return value;
}
}
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment