Traverse the array . If arr [ i ] is non - zero , then swap the element at index ' count ' with the element at index ' i '
for ( int i = 0 ; i < n ; i ++ ) { if ( ( arr [ i ] != 0 ) ) { temp = arr [ count ] ; arr [ count ] = arr [ i ] ; arr [ i ] = temp ; count = count + 1 ; } } }