How to modify this code to print the output in sorted form

#include<bits/stdc++.h>
using namespace std;
void targetSum(int arr[], int n, int s)
{
for (int i=0; i<n; i++){
for (int j=i+1; j<n; j++){
int sum = arr[i]+arr[j];
if (sum==s){
cout<<arr[i]<<" and "<<arr[j]<<endl;
}
}
}

}
int main() {
int n;
cin>>n;
int arr[n];
for(int i=0;i<n;i++){
cin>>arr[i];
}
int x;
cin>>x;
targetSum(arr,n,x);
return 0;
}

hi @discobot sort the array before calling the function

Hi! To find out what I can do, say @discobot display help.

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.