#include
using namespace std;
int main() {
int a[1000],i,size,key,j;
scanf("%d",&size);
for(i=0;i<size;i++)
{
scanf("%d",&a[i]);
}
scanf("%d",&key);
for(i=0,j=size-1;i<j;jβ)
{ //printf(βi=%d j=%dβ,i,j);
if(key==a[i]+a[j])
{
cout<<a[i]<<" and β<<a[j]<<β\n";
}
if(j==i+1)
{
i++;
j=size;
}
}
return 0;
}
Could you please tell me what's wrong in this code?
your ide isnβt generating URL for sharing.
hello @ayushsakure
first sort ur array. (required to print output in ascending order)
and then use two pointers or nested for loops to print all pairs.
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.