The code given below is not satisfying all test cases.
// Array - Target Sum Pair
#include
using namespace std;
int main() {
int n;
cin >> n;
int a[1000] ;
for(int i=0; i<n; i++){
cin >> a[i] ;
}
int target;
cin >> target;
for(int i=0; i<n; i++){
for(int j=i; j<=n; j++){
int sum = a[i] + a[j] ;
if(sum == target){
if(a[i] > a[j]){
cout << a[j] << " and "<<a[i] <<endl;
}
else{
cout << a[i]<< " and "<<a[j] <<endl;
}
}
}
}
return 0;
}