Alright, I know this is a silly question to ask as it is related to reverse for loop but I am struggling to understand this. I even tried to make a separate reverse for loop program to clear the context but I am still in trouble.
So here is my code
#include<iostream>
using namespace std;
int main()
{
int i,d,j=0,b[100];
cin>>d;
while(d>0)
{
b[j]=d%2;
d=d/2;
j++;
}
//cout<<j;
for(i=j-1;i>=0;i--)
{
cout<<b[i];
}
}
Now, please explain me the for-loop. Why it should be i=j-1;i>=0;i--
? Can't it be i=j;i>0;i--
?
When I am giving 109
as input and using i=j;i>0;i--
I am receiving 6946348110110
as output and if I am using i=j;i>=0;i--
then I am receiving 69463481101101
I am a novice. Please help!