Find a pair with sum N having minimum absolute difference | C ++ program to implement the above approach ; Function to find the value of X and Y having minimum value of abs ( X - Y ) ; If N is an odd number ; If N is an even number ; Driver Code
#include <bits/stdc++.h> NEW_LINE using namespace std ; void findXandYwithminABSX_Y ( int N ) { if ( N % 2 == 1 ) { cout << ( N / 2 ) << " ▁ " << ( N / 2 + 1 ) ; } else { cout << ( N / 2 - 1 ) << " ▁ " << ( N / 2 + 1 ) ; } } int main ( ) { int N = 12 ; findXandYwithminABSX_Y ( N ) ; }