#include <stdio.h>
#include <stdlib.h>
/* Puzzle L01 -- print the integers from 0 to 14, one per line */
int main(int argc, char *argv[])
{
int j;
for (j=0; j<15; j++ )
{
printf("%3d\n", j);
}
system("PAUSE");
return 0;
}
Comment: This is the usual way to count from 0 to 14. It
also works to use this for statement:
for (j=0; j<=14; j++ )
Comment:
The system("PAUSE") is needed if you run the program
within the Dev-C++ environment. Without it, the DOS window
vanishes when the program reaches the end and you will not
be able to see the output.
Comment: With most C compilers it would work to do this:
for (int j=0; j<15; j++ )
{
printf("%3d\n", j);
}
Although this works, it is not syntactically correct ANSI C. It is correct C++ which is why it works on most compilers. Some compilers will compile it, but complain.