#include
using namespace std;
int main() {
int a[1000];
int n;
cin>>n;
for(int i=0;i<n;i++)
{
cin>>a[i];
}
int target;
cin>>target;
for(int i=0;i<=n-3;i++)
{
target=target-a[i];
int l=i+1;
int r=n-1;
while(l<r)
{
int c = a[l]+a[r];
if(c==target)
{
cout<<a[i]<<", “<<a[l]<<” and “<<a[r]<<”\n";
l++;
r–;
}
else if(c>target)
{
r–;
}
else
{
l++;
}
}
target = target+a[i];
}
return 0;
}
What is the problem in my code?
you need to sort the array after taking it input
Corrected Code