Answer L3

#include <stdio.h>
#include <stdlib.h>

/* Puzzle L03 -- print the  even integers 0, 2, 4, 6, ... , 20, one per line */
int main()
{
  int j;
  for (j=0; j<=20; j+=2 )
  {
    printf("%3d\n", j);
  }

  return 0;
}

Comments: In some situations it might be more sensible to do this:

  for (j=0; j<=10; j++ )
  {
    printf("%3d\n", 2*j);
  }

This is a matter of taste, and context.



Back to Puzzle Home