Where it is gone wrong

#include
using namespace std;
int target_sum(int *a,int k)
{
int n;

for(int i=0;i<=n;i++)
{
for(int j=i+1;j<=n;j++)
{
if(a[i]+a[j]==k)
{
cout<<a[i]<<" "<<a[j]<<endl;
}
}

}
}
int main()
{
int a[100],n,k;
cin>>n;
for(int i=0;i<=n;i++)
{
cin>>a[i];
}
cin>>k;

cout<<target_sum(a,k)<<endl;
return 0;
}

Hey, pass the size of array in the function argument or make it global and initialize it in the main function so that without passing it in the function parameter it can be used in the calling function

Since u are decalring a int n in target_sum and not giving a value so ur code is not working fine

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.