What's wrong with my code?

#include
using namespace std;

int main() {
int N;
cin>>N;
int target;
cin>>target;
int a[N];
for(int i=0;i<N;i++)
{
cin>>a[i];
}

for(int i=0;i<N;i++)
{
    for(int j=i+1;j<N;j++)
    {
        if(a[i]+a[j]==target)
        {
            cout<<a[i]<<"and"<<a[j]<<endl;  
        }
    }
}
return 0;

}

hello @deepteaman
the logic is correct.
in output file the output is in sorted order.
so to pass all the test cases sort ur input array and then try

#include #include using namespace std; int main() { int N; cin>>N; int target; cin>>target; int a[N]; for(int i=0;i<N;i++) { cin>>a[i]; } sort(a,a+N); for(int i=0;i<N;i++) { for(int j=i+1;j<N;j++) { if(a[i]+a[j]==target) { cout<<a[i]<<" and "<<a[j]<<endl; } } } return 0; }

save this code on cb ide and share its link with me

I hope I’ve cleared your doubt. I ask you to please rate your experience here
Your feedback is very important. It helps us improve our platform and hence provide you
the learning experience you deserve.

On the off chance, you still have some questions or not find the answers satisfactory, you may reopen
the doubt.