Sum of values of all possible non | C # implementation of the approach ; Function to return the required sum ; Find the sum of the array elements ; Every element appears 2 ^ ( n - 1 ) times ; Driver code
using System ; class GFG { static int sum ( int [ ] arr , int n ) { int sum = 0 ; for ( int i = 0 ; i < n ; i ++ ) { sum += arr [ i ] ; } sum = sum * ( int ) Math . Pow ( 2 , n - 1 ) ; return sum ; } public static void Main ( ) { int [ ] arr = { 2 , 1 , 5 , 6 } ; int n = arr . Length ; Console . WriteLine ( sum ( arr , n ) ) ; } }