Sum of all subsets of a set formed by first n natural numbers | CPP program to find sum of all subsets of a set . ; sum of subsets is ( n * ( n + 1 ) / 2 ) * pow ( 2 , n - 1 ) ; Driver code
#include <bits/stdc++.h> NEW_LINE using namespace std ; unsigned long long findSumSubsets ( int n ) { return ( n * ( n + 1 ) / 2 ) * ( 1 << ( n - 1 ) ) ; } int main ( ) { int n = 3 ; cout << findSumSubsets ( n ) ; return 0 ; }