Target sum pairs

showing tle but why

#include
using namespace std;

int main(){
int n;
cin>>n;
int a[100];
for(int i=0;i<n;i++){
cin>>a[i];
}
int x;
cin>>x;
int i=0;
int j=n-1;
while(i<j){

if(a[i]+a[j]==x){
    cout<<a[i]<<" "<<"and"<<" "<<a[j]<<endl;

}
else if(a[i]+a[j]<x){
    i++;
}
else if(a[i]+a[j]>x){
    j--;
}

}

return 0;
}

@kumarakash121005 actually meine jab chalaya toh compilation error de rha tha
because you done mistake in your first if condition after printing you also move both pointers and according to constraint you have taken less size of an array thats why it gives compilation error

@kumarakash121005 https://ide.codingblocks.com/s/645759
see this try this

@kumarakash121005 is it solve or u understood??

solve to ho gya lekin iska implementation target sum triplet nhi ho rha

@kumarakash121005 you asked for target pair sum first

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.

@kumarakash121005 please rate