Test code 2 showing no output

this is my code:

this is also showing right output

but when i submit it shows test code 2 no output…why???

#include

using namespace std;

void sum(int a[],int n,int target)
{
int counter = 1;

while(counter<n)
{

	for(int i=0;i<n-counter;i++)
    {
		if(a[i]>a[i+1])
        {
			swap(a[i],a[i+1]);
		}
	
	}

	counter++;
}

int l=0,r=n-1;

while(l<r)
{
    int sum=a[l]+a[r];
    if(sum==target)
    {
        cout<<a[l]<<" and "<<a[r]<<endl;
    l++;
    // r--;
    }
    // else if(sum>target)
    // {
    // 	r--;
    // }
    r--;
}

}

int main()
{
int a[100],n,target;

cin>>n;

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

cin>>target;

sum(a,n,target);

return 0;

}

@bhuvankumar3c
Try this input.

Input :
3
2 4 4
6

Expected Output :
2 and 4
2 and 4

Your Output :
2 and 4

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.