Advertisement
Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- #include <stdio.h>
- float abs(float x) {
- return x < 0 ? -x : x;
- }
- float fib(int n) {
- if (n == 1 || n == 2) {
- return 1.0;
- }
- return fib(n - 1) + fib(n - 2);
- }
- float phi(float f) {
- float phi_1;
- float phi_2;
- int i;
- for (i = 3;;++i) {
- phi_1 = fib(i) / fib(i + 1);
- phi_2 = fib(i + 1) / fib (i + 2);
- if (abs(phi_2 - phi_1) < f) {
- return phi_2;
- }
- }
- }
- int main(void) {
- printf("%f\n", phi(0.0001));
- return 0;
- }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement