Created
October 28, 2011 06:48
-
-
Save haileys/1321766 to your computer and use it in GitHub Desktop.
This file contains hidden or 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
| #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; | |
| } |
This file contains hidden or 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
| (n -> | |
| 1 => a | |
| 0 => b | |
| for 1 n ( | |
| b => c | |
| a => b | |
| + a c => a | |
| ) | |
| a | |
| ) => fib | |
| fib 100000 |
This file contains hidden or 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
| 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