Skip to content

Instantly share code, notes, and snippets.

@haileys
Created October 28, 2011 06:48
Show Gist options
  • Select an option

  • Save haileys/1321766 to your computer and use it in GitHub Desktop.

Select an option

Save haileys/1321766 to your computer and use it in GitHub Desktop.
#include <stdio.h>
#include <stdlib.h>
double fib(int n)
{
double a = 1, b = 0, c;
int i;
for(i = 1; i <= n; i++) {
c = b;
b = a;
a = a + c;
}
return a;
}
int main()
{
printf("%lf\n", fib(100));
return 0;
}
(n ->
1 => a
0 => b
for 1 n (
b => c
a => b
+ a c => a
)
a
) => fib
fib 100000
def fib(n):
a = 1
b = 0
i = 0
while i < n:
c = b
b = a
a += c
i += 1
return a
fib(100000)
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment