Find K such that | A | Function to find k such that | a - k | = | b - k | ; If ( a + b ) is even ; Driver code
function find_k ( a , b ) { if ( ( a + b ) % 2 == 0 ) return ( ( a + b ) / 2 ) ; return - 1 ; } var a = 2 , b = 16 ; document . write ( find_k ( a , b ) ) ;