Calendar of January

  1. Suppose we know what day January 1st is, it will be straightforward to print the calendar of January, if you follow the steps below.
  2. Suppose the 1st day of January is D, where 0 stands for Sunday and 6 stands for Saturday. Take 2014 for example, D=3.
  3. Before printing the first day, we print out 3*D spaces.
  4. Then we start printing Day 1 to Day 31. Each day will be printed with a width of two columns, right-justified using the setw() function.
  5. A space will be inserted between two days in a line.
  6. After printing a day of Saturday, print a newline character ('\n').
  7. In front of the calendar, you may also add a header "Su Mo Tu We Th Fr Sa" as well as the month name and the year number.

The program may run as follows:

2016
    January 2016
Su Mo Tu We Th Fr Sa
                1  2
 3  4  5  6  7  8  9
10 11 12 13 14 15 16
17 18 19 20 21 22 23
24 25 26 27 28 29 30
31