Print first n Fibonacci Numbers using direct formula | C ++ code to print fibonacci numbers till n using direct formula . ; Function to calculate fibonacci using recurrence relation formula ; Using direct formula ; Driver code
#include <bits/stdc++.h> NEW_LINE using namespace std ; void fibonacci ( int n ) { long long int fib ; for ( long long int i = 0 ; i < n ; i ++ ) { fib = ( pow ( ( 1 + sqrt ( 5 ) ) , i ) - pow ( ( 1 - sqrt ( 5 ) ) , i ) ) / ( pow ( 2 , i ) * sqrt ( 5 ) ) ; cout << fib << " ▁ " ; } } int main ( ) { long long int n = 8 ; fibonacci ( n ) ; return 0 ; }