Make array elements equal with minimum cost | C ++ implementation to make array elements equal with minimum cost ; Function to find the minimum cost required to make array elements equal ; Loop to find the count of odd elements ; Driver Code
#include <bits/stdc++.h> NEW_LINE using namespace std ; void makearrayequal ( int arr [ ] , int n ) { int x = 0 ; for ( int i = 0 ; i < n ; i ++ ) { x += arr [ i ] & 1 ; } cout << min ( x , n - x ) << endl ; } int main ( ) { int arr [ ] = { 4 , 3 , 2 , 1 } ; int n = sizeof ( arr ) / sizeof ( arr [ 0 ] ) ; makearrayequal ( arr , n ) ; return 0 ; }