What is wrong with this code. plz tell and explain

#include
using namespace std;
int main() {
long int n,c,s;
cin>>n;
int arr[1005];
for(int i=1;i<=n;i++)
{
cin>>arr[i];
}
cin>>s;
for(int i=1;i<=n-1;i++)
{
for(int j=1;j<=n-i-1;j++)
{
if(arr[j]>arr[j+1])
{
c=arr[j];
arr[j]=arr[j+1];
arr[j+1]=c;
}
}
}
long int l=1;
long int h=n;
while(l<=h)
{
if(s>(arr[l]+arr[h]))
{
l++;
}
else if(s<(arr[l]+arr[h]))
{
h–;
}
else if(s==(arr[l]+arr[h]))
{
cout<<arr[l]<<" and “<<arr[h]<<”\n";
l++;
h–;
}
}
return 0;
}

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

Check now.

still it is showing test case 3 is wrong

Your sorting is not being done correctly.
Consider this test case and check:
5
5
2
3
4
1
6

https://ide.codingblocks.com/s/234439. this is working fine.but still shows failed test cases.

Run for this test case and check:
6
-3
1
4
3
6
8
9

Follow the 0 indexing of arrays. You taking input from arr[1] ignoring arr[0]. This is causing the issue.

Check now

okay. got it now. thank u for your help.