Not able to solve it

#include
#include
using namespace std;

int main()
{
int N,Target;
cin>>N;
int Array[N];

for (int i = 0; i < N; i++)
{
    cin>>Array[i];
}

cin>>Target;
sort(Array,Array+N);//you have to jsut sort your array before so that the order also gets correct.
int i=0;
    for (int j = 0; j < N/2; j++)
    {
        for (int k = 0; k < N; k++)
        {
            if (Array[i]+Array[j]+Array[k]==Target)
            {
                if ( (Array[i]!=Array[j]) && (Array[j]!=Array[k]) )
                {
                        cout<<Array[i]<<", "<<Array[j]<<" and "<<Array[k]<<"\n";   
                }
            }
        }i++;
    }


return 0; 

}

Hello @rprahulpal03 what is the problem that you are facing?
And could you please share your code by saving it on Ide.codingblocks.com

no error shown in IDE

#include

#include

using namespace std;

int main()

{

int N,Target;

cin>>N;

int Array[N];

for (int i = 0; i < N; i++)

{

    cin>>Array[i];

}

cin>>Target;

sort(Array,Array+N);

int i=0;

    for (int j = 0; j < N/2; j++)

    {

        for (int k = 0; k < N; k++)

        {

            if (Array[i]+Array[j]+Array[k]==Target)

            {

                if ( (Array[i]!=Array[j]) && (Array[j]!=Array[k]) )

                {

                        cout<<Array[i]<<", "<<Array[j]<<" and "<<Array[k]<<"\n";   

                }

            }

        }i++;

    }

    

return 0; 

}

#include #include using namespace std; int main() { int N,Target; cin>>N; int Array[N]; for (int i = 0; i < N; i++) { cin>>Array[i]; } cin>>Target; sort(Array,Array+N);//you have to jsut sort your array before so that the order also gets correct. int i=0; for (int j = 0; j < N/2; j++) { for (int k = 0; k < N; k++) { if (Array[i]+Array[j]+Array[k]==Target) { if ( (Array[i]!=Array[j]) && (Array[j]!=Array[k]) ) { cout<<Array[i]<<", “<<Array[j]<<” and “<<Array[k]<<”\n"; } } }i++; } return 0; }

Hello @rprahulpal03 your code is not giving any output because the condition is not satisfying at any position.

please see this code we have used this three pointer approach.


i have just reframed your logic of using three pointer approach.
if you have any doubt you can ask here
Happy Learning!!

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.