Assuming all the array elements are distinct . Replace the maximum element with the coefficient of range of the array
for ( $ i = 0 ; $ i < $ n ; $ i ++ ) { if ( $ arr [ $ i ] == $ max ) { $ arr [ $ i ] = $ coeffOfRange ; break ; } }