Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

create fibonacci using golden ratio #61

Open
wants to merge 1 commit into
base: master
Choose a base branch
from
Open
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
42 changes: 42 additions & 0 deletions Fibonacci/fibonaaci using golden ratio
Original file line number Diff line number Diff line change
@@ -0,0 +1,42 @@
// C++ program to find n-th fibonacci
#include <bits/stdc++.h>
using namespace std;

// Approx value of golden ratio
double golden = 1.6180339;

int fib[6] = { 0, 1, 1, 2, 3, 5 };

// function to find nth Fibonacci number
int fibonacci (int n)
{

if (n < 6)
return fib[n];

// counting from 5th term
int j = 5, fibn = 5;

while (j < n) {

// function to round off the value
fibn = round(fibn * golden);
j++;
}


return fibn;
}


int main()
{
int n = 9;

// print nth fibonacci

cout << n <<"th Fibonacci:"
<< fibonacci(n) << endl;

return 0;
}