Why is the output differnt

#include
#include
using namespace std;

int main(){
int n,target;
cin>>n;
int a[1000];
if(1<=n<=1000){
for(int i=0;i<n;i++){
cin>>a[i];
}
sort(a,a+n);
cin>>target;
for(int i=0;i<n;i++){
int l=i+1,r=n-1;
while(l<r){
if(a[i]+a[l]+a[r]==target){
cout<<i<<", “<<a[l]<<” and "<<a[r]<<endl;
l++;
r–;
}
else if(a[i]+a[l]+a[r]>target){
r–;
}
else if(a[i]+a[l]+a[r]<target){
l++;
}
}
}
}

return 0;
}

The Code is almost same but i dont know why am i getting a different output.

You need to print a[i] not i.

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.