Code :-
#include<bits/stdc++.h>
using namespace std;
void targetSum(int arr, int n, int target)
{
int left = 0;
int right = n - 1;
while (left <= right)
{
int sum = arr[left] + arr[right];
if (sum > target)
{
right++;
}
else if (sum < target)
{
left–;
}
else
{
cout >> arr[left] << " and " << arr[right] << endl;
left–;
right++;
}
}
}
int main() {
int n;
cin>>n;
int arr[n];
for(int i=0;i<=n;i++){
cin>>arr[i];
}
int x;
cin>>x;
targetSum(arr,n,n);
return 0;
}
Code is giving Error. Question is to find the pair in array whose sum is equal to num
kindly share the link of your code
save your code at https://ide.codingblocks.com/
and share the url generated
Also this was the default code in ide when I started the problem.
Modified Code
i have corrected all the mistakes you have done
if you any further doubt feel free to ask
can you tell me what I was the problem in code. As I have also tried to correct and after correcting the array syntax in parameter and cout << , it give segmentation error like this!
join this meet i will explain all your mistakes
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.
My testcases are failing in this problem !! Even after I unlocked the editorial.
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.
