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);
}