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