Created
June 10, 2014 20:37
-
-
Save MaheshReddy/101a1a03b98849a4ada8 to your computer and use it in GitHub Desktop.
simple function to generate Fibonacci series.
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
float golden_ratio = 1.61803398874989484820; | |
float root_5 = 2.2360679774997896964091736687313; | |
int get_fibonacci(int n){ | |
float fib_num = 0.0; | |
fib_num = (powf(golden_ratio,(float)n) - powf(1 - golden_ratio,(float)n)) / root_5; | |
return (int)fib_num; | |
} |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment