Where i am going wrong

#include
using namespace std;

int main(){
int n;
cin>>n;
int a[1000];
for(int i=0;i<n;i++){
cin>>a[i];
}
int s;
cin>>s;

int i=0;
int j=sizeof(a)/sizeof(int) -1;

while(i<j){
	int curr= a[i] + a[j];
	
	if(curr<s){
		i++;
	}
	else if(curr>s){
		j--;
	}
	else if(curr == s){
		cout<<a[i]<<"and"<<a[j]<<endl;
		i++;
		j--;
	}
	
}

}

hello @anuragsen9617

u have declared 1000 size array , so this will always result into 999 which is wrong.

use n-1 instead.

add space around and

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.