#include
using namespace std;
int main()
{
int a[3]={1,3,5};
int n=3;
int number=6;
int i=0,j=n-1;
while(i>j)
{
if(a[i]+a[j]==number)
{
cout<<a[i]<<" "<<a[j]<<endl;
i++;
j–;
}
else if(a[i]+a[j]>number)
{
j–;
}
else if(a[i]+a[j]<number)
{
i++;
}
}
return 0;
}
Whats wrong with my code. please tell me
Perhaps you are not getting desired output . Try while(i<j) in place of while(i>j).
You can elaborate if you are still not getting desired output.