include
using namespace std;
void sum(int n,int a[],int target){
int i,j;
if( j!=i){
for(i=0;i<n;i++){
for(j=i+1;j<n;j++){
if(a[i]+a[j]==target){
cout<<a[i]<<","<<a[j]<<endl;
}
}
}
}
}
int main()
{
int n;
cin>>n;
int a[1000],i;
if(n>0){
int a[n];
for(i=0;i<n;i++){
cin>>a[i];
}
int target;
cin>>target;
sum(n,a,target);
}
return 0;
}
this is my code
My test cases are not passing
ake as input N, the size of array. Take N more inputs and store that in an array. Take as input “target”, a number. Write a function which prints all pairs of numbers which sum to target. Input Format The first line contains input N. Next N lines contains the elements of array and (N+1)th line contains target number. Constraints Length of the arrays should be between 1 and 1000. Output Format Print all the pairs of numbers which sum to target. Print each pair in increasing order. Sample Input 5 1 3 4 2 5 5 Sample Output 1 and 4 2 and 3
this is question of that code
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.