Find K such that | A | C ++ implementation of the approach ; Function to find k such that | a - k | = | b - k | ; If ( a + b ) is even ; Driver code
#include <bits/stdc++.h> NEW_LINE using namespace std ; int find_k ( int a , int b ) { if ( ( a + b ) % 2 == 0 ) return ( ( a + b ) / 2 ) ; return -1 ; } int main ( ) { int a = 2 , b = 16 ; cout << find_k ( a , b ) ; return 0 ; }