Problem in array target sum pairs ques

I have solved this ques and when I am running in my vs code and online compiler everything looks fine but when I am running on code-blocks compiler it is showing wrong outputs. I have even tried with long int thenalso no difference. PLEASE SEE THIS

#include
using namespace std;

void pairFinder(int a[], int n, int s)
{
int i = 0, j = n - 1;

while (i < j)
{
    int current_sum = a[i] + a[j];
    if (current_sum > s)
    {
        j--;
    }
    else if (current_sum < s)
    {
        i++;
    }
    else if (current_sum == s)
    {

        cout << a[i] << " and " << a[j] << endl;
        i++;
        j--;
    }
}

}

int main()
{

int n;

cin >> n;

int a[n];

for (int i = 0; i < n; i++)
{
    cin >> a[i];
}
int s;
cin >> s;
pairFinder(a, n, s);

}

Everything is right, you just forgot to sort the array before operating on it. In question, it’s not given that the array is sorted. So you have to sort the array to.

understood thank you

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.

how do i sort the array in this code particularly ??? can anyone help?