Find nth Fibonacci number using Golden ratio | CPP program to find n - th Fibonacci number ; Approximate value of golden ratio ; Fibonacci numbers upto n = 5 ; Function to find nth Fibonacci number ; Fibonacci numbers for n < 6 ; Else start counting from 5 th term ; driver code
#include <bits/stdc++.h> NEW_LINE using namespace std ; double PHI = 1.6180339 ; int f [ 6 ] = { 0 , 1 , 1 , 2 , 3 , 5 } ; int fib ( int n ) { if ( n < 6 ) return f [ n ] ; int t = 5 , fn = 5 ; while ( t < n ) { fn = round ( fn * PHI ) ; t ++ ; } return fn ; } int main ( ) { int n = 9 ; cout << n << " th ▁ Fibonacci ▁ Number ▁ = ▁ " << fib ( n ) << endl ; return 0 ; }