Correct output but still isnt getting submitted

My code is giving the correct output for all the testcases but it still shows error in two testcases while submitting. Does the method needs to be the exact for it to get submitted?
#include
using namespace std;
int main() {
int n=0;
cin>>n;
int arr[n]={0};
for(int i=0;i<n;i++){
cin>>arr[i];
}
int target=0,x=0;
cin>>target;
for(int i=0;i<n;i++){
x=arr[i];
for(int j=i;j<n;j++){
if(n==1){
cout<<arr[i]<<" and “<<arr[i]<<endl;
}
if(arr[j]==target-x){
cout<<arr[i]<<” and "<<arr[j]<<endl;
break;
}
}
}
return 0;
}

for input
5
1
3
4
2
5
4
correct output
1 3

your Output
1 and 3
2 and 2

because 2 comes only once in the array

i edited the code and nowit is showing the correct output but still cannot submit it

in question it is mention that
Print each pair in increasing order.

so first you have to sort the array

Modified Code

1 Like

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.