Array-target sum pairs

when giving the custom input,output is exactly the same which is needed but when i’m trying to submit the code, two test cases are passed an two are wrong.Where is the problem in code below:
#include
using namespace std;
int main() {
int n;
cin>>n;
int a[1000];
for(int i=0;i<=n;i++){
cin>>a[i];
cout<<endl;
}

for(int i=0;i<n;i++){
    for(int j=i;j<n;j++){
        if((a[i]+a[j])==a[n]){
            cout<<a[i]<<" and "<<a[j]<<endl;
        }
    }
}

return 0;

}

Hi Mudit

  1. You have not taken input of target number. Use that in a[i] + a[j] == target
  2. use for(j=i+1;j<n;j++)
  3. check out for duplicates in array. You should not print duplicate pairs. For this you should sort the array and skip the ith element if its same as its previous element.

Hope it helps
Please mark resolved if satisfief :slight_smile:

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.