Sir,output not showing nd also check the approch first i sort the array then i use two pointer method
There are multiple issues with your code,
- you haven’t input n
if(cs<s){
i++;
}
else if(cs<s){
j--;
}
both are same condition
- Try using this approach, as sorting array is must which you have already done
for(int i=0; i<n-1; i++){
for(int j=i; j<=n-1; j++){
if(a[i] + a[j] == target && a[i] != a[j]){
cout<<a[i]<<" and "<<a[j]<<endl;
}
}
}
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.