Arrays- target sum pairs

This is my code. The only thing I’m unable to do is arrange the pairs in increasing order. I think it can be done using vectors, but that hasn’t been covered in the course yet. What else can I do?

#include
using namespace std;
int main()
{
int n;
cin>>n;

int arr[n];
for (int i=0; i<n; i++)
{
	cin>> arr[i];
}

int key;
cin>>key;



for (int a=0; a<n; a++)
{
	for (int b=a+1; b<n; b++)
	{
		int sum= arr[a] + arr[b];
		if (sum==key)
		{
			
			cout << arr[a] << " and " << arr[b] << endl;
		}
	}

}
return 0;

}

hello @yamika

sort ur array becuase in output file output are in sorted order

yes i did that, thanks :slight_smile:

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.