i cannot figure out my mistake
#include
using namespace std;
int main() {int n;
cin>>n;
int a[999];
for(int i=0;i<n;i++){
cin>>a[i];
}int goal;
cin>>goal;
for(int i=0;i<(n/2);i++){
for(int j=(n-1);j>=(n/2);jβ){
int sum=a[i]+a[j];
if(sum==goal){if(a[j]>a[i]){
cout<<a[i]<<" β<<βandβ<<β β<<a[j]<<endl;}
if(a[j]<a[i]){
cout<<a[j]<<β β<<βandβ<<β "<<a[i]<<endl;
}
}
}
}
return 0;
}
Test case 2 shows wrong answer
but is this code wrong?
that will further increase the number of loops though
my way seems pretty convinient
i see now it works but still i dont know rightly why it showed an error coz even now the code remains same except that sort line by youβ¦