TargetSum Pairs

The output seems ambiguous. There could be repetitions of pairs… and if I include only one such pair, the order of output may be different in some cases from the output expected …
eg : 1 and 4 may be the expected output but my answer could be 4 and 1. please help with this.

my code :

#include
using namespace std;
int main() {
int n;
cin>>n;
int a[n+1];
for(int i=0;i<n;i++)
cin>>a[i];
int t;
cin>>t;

for(int i=0;i<n;i++)
   {
       for(int j=i;j<n;j++)
       {
           if(a[i]+a[j]==t)
           {
           int s = (a[i]<a[j]) ? a[i] : a[j];
            //cout<<a[i]<<" and "<<a[j]<<endl;
          cout<< s << " and " << 5-s << endl;
           }
       }
   }

return 0;

}