Getting wrong answer

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

void target_sum(int arr[],int n,int target){
int i=0;
int j=n-1;
while(i<=j && i<n && j>=0){
if(arr[i]+arr[j]==target){
cout<<arr[i]<<" and "<<arr[j]<<endl;
i++;
j–;
}
else if(arr[i]+arr[j]>target)
j–;
else
i++;
}
}

int main()
{
int n;
cin>>n;
int arr[n];
for(int i=0;i<n;i++){
cin>>arr[i];
}
int target;
cin>>target;
sort(arr,arr+n);
target_sum(arr,n,target);

}

hi @gunvirmittal_9f1753c05330d09c print unique triplet

5
1 1 1 1 1
3

refer https://ide.codingblocks.com/s/656672 ive commented the code

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.