Target sum pair 1

i want to know that why testcase 4 is failing

Hey mohammad, copy you code on coding blocks IDE and save it, then send the link

https://ide.codingblocks.com/s/63180

https://ide.codingblocks.com/s/63180 here is the link to the code

Hi, for this part of your code:

for(int i=0;i<n;i++)
{
for(int j=i+1;j<n;j++)
{
if(a[i]+a[j]==target and a[i]<=a[j]){
cout<<a[i]<<" and "<<a[j]<<endl;
}
}
}
You were initialising j with 0 and thus a single number was being considered twice. Just initialise j with i+1 and the code will work fine. I’ve done it here for your reference: https://ide.codingblocks.com/s/63363

Hi Mohammad , as you are not responding to this thread, I am marking your doubt as Resolved for now. Re-open it if required.

Please mark your doubts as resolved in your course’s “ Ask Doubt ” section, when your doubt is resolved.

can you tell me that what is the need of sorting an array?

can anyone tell me why the test case 4 not running