Target sum pair

Sir, for the problem target sum pair in the array challenge section one test case is not passing?Problem.
My code:-

#include
using namespace std;
int main(){
int a[999];
int n;
cin>>n;
for(int i=0;i<=n-1;i++){
cin>>a[i];
}
int ta;
cin>>ta;
for(int i=0;i<n;i++){
for(int j=1;j<n;j++){
if(a[i]+a[j]==ta && a[i]<=a[j]){
cout<<a[i]<<" “<<“and”<<” "<<a[j]<<endl;
}
}

}
}

Your logic is nearly coorect, but your code does not handle some cases.

You can refer my code https://ide.codingblocks.com/s/41561
You can easily understand from it.

Hi, Sachin
I tried getting the answer in O(n), but somehow it’s failing in some unknown test cases.
https://ide.codingblocks.com/s/47668
Could you kindly have a look and tell me where it fails.

Hey Simrandeep, your code is not able to handle some corner cases. for example
input:
5
5
2
3
4
1
6

your code’s output:
1 and 5
2 and 4
3 and 3

but the correct output should be :
1 and 5
2 and 4

The code required a slight correction. I made it and got a 100.
Here’s the new code - https://ide.codingblocks.com/s/47847
Thanks man.