I have two vectors _A and _B and an equation (x-y)/2, where the x is vector _A and y is _B. So for example _A={8,1,16} and B={4,1,8} my output should be all the combinations that give a postive integer greater than 0 so {(8,4),(16,8)}. How can i make it output only the numbers that work for this equation.
My Code for the function:
for(int i =0; i<_A.size(); i++){
for(int j=0; j<_B.size();j++){
int INT =( _A.at(i) - _B.at(j))/2;
if (INT % 1 == 0 && INT > 0) {
cout << "{";
for(int i =0; i<_A.size();i++){
#include <iostream>
#include <vector>
usingnamespace std;
vector<pair<int,int>> evenPositiveDifference( const vector<int> &A, const vector<int> &B )
{
vector<pair<int,int>> result;
for ( int x : A )
{
for ( int y : B ) if ( x > y && ( x - y ) % 2 == 0 ) result.push_back( { x, y } );
}
return result;
}
int main()
{
vector<int> A = { 8, 1, 16 }, B = { 4, 1, 8 };
for ( auto p : evenPositiveDifference( A, B ) ) cout << p.first << ", " << p.second << '\n';
}