text: Minimum increment and decrement by K of each pair elements required to make all array elements equal | C ++ program for the above approach ; Function to check if its possible to make all array elements equal or not ; Stores the sum of the array ; Traverse the array ; If sum is divisible by N ; Otherwise , not possible to make all array elements equal ; Driver Code ; Given array ; Size of the array
code: #include <bits/stdc++.h> NEW_LINE using namespace std ; void arrayElementEqual ( int arr [ ] , int N ) { int sum = 0 ; for ( int i = 0 ; i < N ; i ++ ) { sum += arr [ i ] ; } if ( sum % N == 0 ) { cout << " Yes " ; } else { cout << " No " << endl ; } } int main ( ) { int arr [ ] = { 1 , 5 , 6 , 4 } ; int N = sizeof ( arr ) / sizeof ( arr [ 0 ] ) ; arrayElementEqual ( arr , N ) ; }