I am a beginner in C++ and may be the question is very basic but I am not understanding the point. I have an array which is {10,20,30,40,50,60,70,80,90,100}; and I want to print it like {100,90,80,70,60,50,40,30,20,10}. I also have the below code for this:
#include <iostream>
using namespace std;
int main()
{
int ara[] = {10, 20, 30, 40, 50, 60, 70, 80, 90, 100};
int i, j, temp;
for(i = 0, j = 9; i < 10 && i<j; i++, j--) {
temp = ara[j];
ara[j] = ara[i];
ara[i] = temp;
}
for(i = 0; i < 10; i++) {
cout<<ara[i]<<endl;
}
return 0;
}
But I am not sure why I am using && i<j
in the below line. If I do not use it then my array out put comes like {10,20,30,40,50,60,70,80,90,100};
I want a clear explanation so that I can understand.
for(i = 0, j = 9; i < 10 && i<j; i++, j--) {