Where am I doing it wrong?

I have my code for this problem, but it misses one output always.

for this input:-

9
5 7 9 1 2 4 6 8 3
10

my output is:-
1, 2 and 7
1, 3 and 6
1, 4 and 5

but there is one more possible output which is 2, 3 and 5
that my code is missing.

please tell me where am i doing it wrong.

int main() {

int n, a[1000], target;
cin>>n;
for(int i=0; i<n; i++){
	cin>>a[i];
}
sort(a,a+n);
cin>>target;
sort(a,a+n);
int end=n-1;
for(int i=0; i<n-2; i++){

	int start=i+1;

	while(start<end){
		if(a[i]+a[start]+a[end]>target){
			end--;
		}
		else if(a[i]+a[start]+a[end]<target){
			start++;
		}
		else if(a[i]+a[start]+a[end]==target){
			cout<<a[i]<<", "<<a[start]<<" and "<<a[end]<<endl;
			start++;
			end--;
		}
	}

}

return 0;

}

please share your code through ide.codingblocks.com

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.