Why testcases are failing?

#include<bits/stdc++.h>
using namespace std;

void twoNumberSum(int arr[], int targetSum, int n) {
sort(arr, arr + n);
int L = 0;
int R = n - 1;

while (L < R)
{
	if (arr[L] + arr[R] < targetSum)
	{
		L = L + 1;
	}
	else if (arr[L] + arr[R] > targetSum) {
		R = R - 1;
	}
	else if ( arr[L] + arr[R] == targetSum)
	{
		cout << arr[L] << "and" << arr[R] << "\n";
	}

}

}

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

twoNumberSum(arr, targetSum, n);
return 0;

}

give space between number and string and.

Sry sir but can you explain more?

you should write cout<<arr[L]<<" and “<<arr[R]<<”\n"; give space between arr[L] , “and” , arr[R]

Sir i did it’s still not working not giving all pairs and running infinte loop

please help what’s wrong in code

please help what’s wrong in code asap

Break from the loop when u find the pair.

I did but Sir not giving all pairs

Try the following:
for(int i=0;i<n;i++)
{
for(int j=i+1;j<n;j++)
{
if(a[i]+a[j]==target and a[i]<=a[j]){
cout<<a[i]<<" and "<<a[j]<<endl;
}
}
}