Triplet problem

Getting a run time error on the following code

#include
using namespace std;

int main()
{
int n,A[1000];
cin>>n;
for(int i=0;i<n;i++)
{
cin>>A[i];
}
int sum ;cin>>sum;
//int size = sizeof(A) / sizeof(A[0]);
//triplet(A, n, sum);
for (int i = 0; i < n - 2; i++)
{
for (int j = i + 1; j < n - 1; j++)
{
for (int k = j + 1; k < n; k++)
{
if (A[i] + A[j] + A[k] == sum)
{
cout << "Triplet is " << A[i] <<
", " << A[j] << "and " << A[k];
return true;
}
}
}
}
return 0;
}

Save your code on ide.codingblocks.com and then share its link.

Your code is not giving output properly. Match the output pattern with the sample output given in the question. Also there is some issue with the nested loops you have used.

Check this and dry run

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.