#include <bits/stdc++.h>
using namespace std;
int main()
{
int n;
cin>>n;
int arr[1005];
for(int i=0;i<n;i++)
{
cin>>arr[i];
}
int k;
cin>>k;
for(int i=0;i<n;i++)
{
for(int j=i;j<n;j++)
{
if(arr[i] + arr[j]==k)
{
cout<< arr[i] << " and " << arr[j] << endl;
}
}
}
return 0;
}
2 taste case getting fail
@shdanish1508
hello SARWARUL,
a)
ur j should start from i+1
b)
here first print minimum of arr[i] and arr[j] and then maximum among them.
hey i don’t find any difference in the code
except j=i+1 and rest is same
hey i don’t find any difference in the code
except j=i+1 and rest is same
see let say if 2 and 3 is the output u want to print .
then first print 2 and then 3.
it will give error if u print 3 and 2
yes i can see in the test case… but where i am making the error
cout<< arr[i] << " and " << arr[j] << endl;
this line should be
cout<<min(arr[i],arr[j])<<" and "<<max(arr[i],arr[j])<<endl;
rest evrything is correct in ur 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.