Check if sum of the given array can be reduced to 0 by reducing array elements by K | C # program for the above approach ; Function to check if the sum can be made 0 or not ; Stores sum of array elements ; Traverse the array ; Driver Code ; Given array [ ] arr
using System ; class GFG { static int sumzero ( int [ ] arr , int N , int K ) { int sum = 0 ; for ( int i = 0 ; i < N ; i ++ ) { sum += arr [ i ] ; } if ( sum == 0 ) Console . Write ( " Yes " ) ; else if ( sum > 0 ) { if ( sum % K == 0 ) Console . Write ( " Yes " ) ; else Console . Write ( " No " ) ; } else Console . Write ( " No " ) ; return 0 ; } public static void Main ( String [ ] args ) { int K , N ; int [ ] arr1 = { 1 , - 6 , 2 , 2 } ; K = 1 ; N = arr1 . Length ; sumzero ( arr1 , N , K ) ; } }