Sum of squares of Fibonacci numbers | C ++ Program to find sum of squares of Fibonacci numbers ; Function to calculate sum of squares of Fibonacci numbers ; Initialize result ; Add remaining terms ; Driver program to test above function
#include <bits/stdc++.h> NEW_LINE using namespace std ; int calculateSquareSum ( int n ) { if ( n <= 0 ) return 0 ; int fibo [ n + 1 ] ; fibo [ 0 ] = 0 , fibo [ 1 ] = 1 ; int sum = ( fibo [ 0 ] * fibo [ 0 ] ) + ( fibo [ 1 ] * fibo [ 1 ] ) ; for ( int i = 2 ; i <= n ; i ++ ) { fibo [ i ] = fibo [ i - 1 ] + fibo [ i - 2 ] ; sum += ( fibo [ i ] * fibo [ i ] ) ; } return sum ; } int main ( ) { int n = 6 ; cout << " Sum ▁ of ▁ squares ▁ of ▁ Fibonacci ▁ numbers ▁ is ▁ : ▁ " << calculateSquareSum ( n ) << endl ; return 0 ; }