I anticipated it would produce:
10 5 3 2 1
but instead it prints
10 5 3 2 1 1 1 1 1 1 1 1 1...
Why?
#include <stdio.h>
int main(void)
{
int i;
for(i = 10; i >= 1; i /= 2)
printf("%d ", i++);
return 0;
}
2 is printed, then one is added making it 3, divided by 2 is 1. As 1 is equal to 1, 1 is printed and then one is added making it 2, divided by 2 is 0. As 0 is less than 1, the loop should end.