Array target sum pairs

#include
using namespace std;
int main() {
short int n,t;
cin>>n;
int a[n];
for(int i=0;i<n;i++){
cin>>a[i];
}
cin>>t;
for(int i=0;i<n;i++){
for(int j=i+1;j<n;j++){
if(a[i]+a[j]==t){
cout<<a[i]<<" and "<<a[j]<<endl;
}
}
}
return 0;
}
sir why this code is correct for only 2 test cases and showing wrong answer for remaining 2 test cases though it is showing correct output in codeblocks.

@gouravemmanuel hey gourav the output is in sorted order.

@gouravemmanuel try to sort the array.

yes i got thank you