Find sum of all nodes of the given perfect binary tree |  ; function to find sum of all of the nodes of given perfect binary tree ; no of leaf nodes ; sum of nodes at last level ; sum of all nodes ; Driver Code
#include <bits/stdc++.h> NEW_LINE using namespace std ; int sumNodes ( int l ) { int leafNodeCount = pow ( 2 , l - 1 ) ; int sumLastLevel = 0 ; sumLastLevel = ( leafNodeCount * ( leafNodeCount + 1 ) ) / 2 ; int sum = sumLastLevel * l ; return sum ; } int main ( ) { int l = 3 ; cout << sumNodes ( l ) ; return 0 ; }