Target sum problem

#include
using namespace std;
void sortarr(int arr[],int n)
{
for(int i=0;i<n;i++)
{
for(int j=0;j<n;j++)
{
if(arr[j]>arr[j+1])
{
int temp;
temp=arr[j];
arr[j]=arr[j+1];
arr[j+1]=temp;
}
}
}
}
void printPairs(int arr[], int n, int target)
{
int l=0;
int r=n-1;
while(l<r)
{
while(l+r>target)
{
r–;
}
if(l+r==target)
{
cout<<l<< " and " <<r<<endl;
}
l++;
}
}
int main()
{
int n,arr[10];
cin>>n;
for(int i=0;i<n;i++)
{
cin>>arr[i];
}
int target;
cin>>target;
sortarr(arr,n);
printPairs(arr,n,target);
return 0;
}
my code is this and i have checked your tutorial also it matches with it but still my two test cases are showing wrong ans ? Help me to figure it out.

Plz send your code by saving on ide.

#include using namespace std; void sortarr(int arr[],int n) { for(int i=0;i<n;i++) { for(int j=0;j<n;j++) { if(arr[j]>arr[j+1]) { int temp; temp=arr[j]; arr[j]=arr[j+1]; arr[j+1]=temp; } } } } void printPairs(int arr[], int n, int target) { for(int i=0;i<(n-1)/2;i++){ int l=i+1; int r=n-1; while(l<r) { while(arr[l]+arr[r]>=target || arr[l]+arr[r]>target-arr[i]) { r–; } if(arr[i]==arr[l]||arr[l]==arr[r]||arr[i]==arr[r]) { break; } if(arr[l]+arr[r]==target-arr[i] && l<r) { cout<<arr[i]<< ", " <<arr[l]<< " and "<<arr[r]<<endl; } l++; } }} int main() { int n,arr[10]; cin>>n; for(int i=0;i<n;i++) { cin>>arr[i]; } int target; cin>>target; sortarr(arr,n); printPairs(arr,n,target); return 0; }

what is ide? haw can i send my code? are you saying email or something else plz mention

type " https://cb.lk/ide " and then paste your code over there, on the top there will be a save button, click it,
Once you are done with it, a random no code will be generated, copy that complete url and then send it here