#include <stdio.h> #include <stdlib.h> /* Puzzle A04 -- print the integers from -7 to +7, one per line */ int main() { int j; for (j= -7; j<= 7; j++ ) { printf("%3d\n", j); } return 0; }
Comments: The above for
statement is a
sensible way to do this.
Would the following version also work, do you think? Or is there an off-by-one error lurking in the code?
#include <stdio.h> #include <stdlib.h> /* Puzzle A04 -- print the integers from -7 to +7, one per line */ int main() { int j; for (j= 0; j<= 14; j++ ) { printf("%3d\n", j-7 ); } return 0; }