Https://online.codingblocks.com/player/8634/content/4812?s=1622

Question is ---- https://online.codingblocks.com/player/8634/content/4812?s=1622

#include
using namespace std;
int main() {

int n;
cin>>n;
int arr[n];
for(int i=0;i<n;i++){
cin>>arr[i];
}
int key;
cin>>key;

int pairSum=0;
for(int i=0;i<n;i++){
for(int j=i+1;j<n;j++){
pairSum=arr[i]+arr[j];
if(pairSum==key)
cout<<arr[i]<<" and "<<arr[j]<<endl;
}
}

return 0;

}

Can you please tell me where i am wrong as 2 testcases of mine are not correct?

You are supposed to write pairs in sorted order, so sort the given array after taking input. I think this will work.

First sort the array, then apply your logic, so that you get the terms of pair in sorted manner.