Arrays-Target Sum Pairs

Why my code gives only a single pair forming target sum ?

#include
using namespace std;

int main()
{
int n;
cin>>n;

int a[n];

for(int i=0;i<n;i++)
cin>>a[i];

int target;
cin>>target;

int l=0, r=n-1;

while(l<r)
{
   if(a[l]+a[r]==target)
   {
       cout<< a[r] << " and " << a[l]<< endl;
       l++;
       r--;
       continue;
   }

  if((a[l] + a[r]) < target)
   l++;

   else r--;
}

}

@vaishnavtannu Hey Vaishnavi, You also need to sort the array before proceeding with your method. You have missed that. Please refer the hint video if you are unable to understand.