Help me debug this code its runtime error,cant find the problem anywhere

#include
using namespace std;

int main() {
int n,ar[100],temp=0,i=0,end;
cin>>n;
for(int i=0;i<n;i++){
cin>>ar[i];
}
end=n-1;
while(i<end)
{
temp=ar[i];
ar[i]=ar[end];
ar[end]=temp;
i++;
end–;
}
for(i=0;i<n;i++){
cout<<ar[i]<<’ ';
}
return 0;
}

Please either format your code or (better!) link to your submission - the forum software has mangled it and it won’t compile! :slight_smile:

Also - what Problem are you trying to solve?

1 Like

From the code, I think he is trying to swap the first and last number, second and second last number and so on

1 Like

Sure, but what are the Constraints, etc?

1 Like

if its a problem from codechef then make sure to scan testcase that’s may be one of the reason for runtime error.
2ndly try to initalize that “i” pointer to zero again before the while loop. Because some times the pointers stores the garbage values may be this works for you