#include <bits/stdc++.h>
using namespace std;
int main() {
int n;
cin>>n;
int* ptr=new int[n];
for(int i=0;i<n;i++){
cin>>ptr[i];
}
sort(ptr,ptr+n);
int key;
cin>>key;
for(int i=0;i<n;i++){
for(int j=i;j<n;j++){
if(ptr[i]+ptr[j]==key)
cout<<ptr[i]<<" and "<<ptr[j]<<endl;
}
}
delete [] ptr;
return 0;
}
Please explain me the exception case.