Split N into two integers whose addition to A and B makes them equal | C ++ Program to implement the above approach ; Function to calculate the splitted numbers ; Calculate X ; If X is odd ; No pair is possible ; Otherwise ; Calculate X ; Calculate Y ; Driver Code
#include <bits/stdc++.h> NEW_LINE using namespace std ; void findPair ( int A , int B , int N ) { int X , Y ; X = N - B + A ; if ( X % 2 != 0 ) { cout << " - 1" ; } else { X = X / 2 ; Y = N - X ; cout << X << " ▁ " << Y ; } } int main ( ) { int A = 1 ; int B = 3 ; int N = 4 ; findPair ( A , B , N ) ; return 0 ; }