Target sum triples . Please tell why my code is not outputting


#include
using namespace std;
#include
void triplet(int arr[],int n,int key){
for(int i=0;i<n;i++){
int start = i+1;
int end = n-1;
int t =arr[i];
int s = arr[start] + arr[end] + t;
while(end>start){
if(key==s){
cout<<arr[i]<<", “<<arr[start]<<” and "<<arr[end]<<endl;
start++;
end–;
}
else if(key>s){
start++;
}
else if(key<s){
end–;
}
}
}

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

hey @yashratnani6 wait let me go through the code .

hey @yashratnani6 please see the correct code in the link below :


i have commented the mistake.
if you feel that you have any doubt you can ask here .
and if your doubt is cleared please mark this doubt as resolved and give the star ratings after marking the doubt as resolved .
Happy Learning !!