Tarrget sum pair

i am getting output 0 and 0
#include<bits/stdc++.h>
using namespace std;

int main(){
int n,i,j,key;
cin>>n;
int a[n];
for(i=0;i<n;i++){
cin>>a[i];
}

cin>>key;

for(i=0;i<n-1;i++){
	for(j=i+1; j<n;j++){
		
		if(a[i]+a[j]==key){
			cout<<a[i]<<" "<<"and"<<" "<<a[j]<<endl;

	}
	}
}

return 0;

}

@adarshsingh2k you have to print all the pairs in sorted order.
if the doubt gets cleared dont forget to hit like and mark resolved :smiley:

can you help me with code

ok wait some time @adarshsingh2k

@adarshsingh2k here just sorted the array


it passes all cases

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.