Skip to content

Instantly share code, notes, and snippets.

@nandavelugoti
Created August 25, 2019 16:44
Show Gist options
  • Save nandavelugoti/b07718480c02725db16d6c415054399f to your computer and use it in GitHub Desktop.
Save nandavelugoti/b07718480c02725db16d6c415054399f to your computer and use it in GitHub Desktop.
// Nth fibonacci number
#define N 10
#include <stdio.h>
long fib(int n) {
long prevFib = 0;
long fib = 1;
int i;
for(i=2; i<=n; i++) {
long nextFib = fib + prevFib;
prevFib = fib;
fib = nextFib;
}
return fib;
}
int main() {
printf("%ld\n", fib(N));
return 0;
}
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment