Sum of Fibonacci Numbers | Set 2 | C ++ program for the above approach ; Function to find the sum of first N + 1 fibonacci numbers ; Apply the formula ; Print the result ; Driver Code ; Function Call
#include <bits/stdc++.h> NEW_LINE using namespace std ; void sumFib ( int N ) { double num = ( 1 - sqrt ( 5 ) ) / 2 ; long val = round ( abs ( 1 / ( pow ( num , N + 2 ) + pow ( num , N + 1 ) + pow ( num , N ) + pow ( num , N - 1 ) ) ) - 1 ) ; cout << val ; } int main ( ) { int N = 3 ; sumFib ( N ) ; }