Element equal to the sum of all the remaining elements | C # implementation of the above approach ; Function to find the element ; sum is use to store sum of all elements of array ; iterate over all elements ; Driver code
using System ; class GFG { static int findEle ( int [ ] arr , int n ) { int sum = 0 ; for ( int i = 0 ; i < n ; i ++ ) sum += arr [ i ] ; for ( int i = 0 ; i < n ; i ++ ) if ( arr [ i ] == sum - arr [ i ] ) return arr [ i ] ; return - 1 ; } static public void Main ( String [ ] args ) { int [ ] arr = { 1 , 2 , 3 , 6 } ; int n = arr . Length ; Console . WriteLine ( findEle ( arr , n ) ) ; } }