Target sum pair(test case 4)

wrong answer in test case 4
code:-

#include
using namespace std;

int main()
{
int N, target,sum=0,a[1000];
cin >> N;

for (int i = 0; i < N; i++)
	cin >> a[i];

cin >> target;

for (int i = 0; i < N ; i++)
{
	for (int j = i; j < N; j++)
	{
		sum = a[i] + a[j];

		if (sum == target) 
		{
			if (a[i] < a[j])
				cout << a[i] << " and " << a[j];
			else
				cout << a[j] << " and " << a[i];
		}
		sum = 0;
	}
	cout << endl;
}
return 0;

}

please tell me where to make the correction.

hey @S19LPN0126, just start inner for loop from i+1. here is your updated code https://ide.codingblocks.com/s/109093

1 Like

hey @S19LPN0126 , if your query is resolved. Please mark this doubt as resolved and rate me on the basis of your experience.
rating option will appear when to mark this doubt as resolved

hey @S19LPN0126, are you facing any problem with this code.

no , they temporarily blocked me from replying.
i got the code, j=i is reading the same number twice.
thanks by the way :slight_smile:

hey @S19LPN0126, if you have no query now, please mark this doubt as resolved.