What day is the first day of a month?
- We have learned how to calculate the
Day Number of a specific day in a month,
and how to calculate
what day January 1st of a specific year is.
- Combining the above two programs, we can easily calculate what day
the first day of a month is.
- Suppose in a year, January 1st is on day D, and the "Day Number" of
the first day of a month is N, then the first day of that month is on
day (N + D - 1) % 7.
(0:Sunday 6:Saturday)
- For example, in November of 2014, D = 3 and N = 305.
- Write a program that accepts a date in the form "YYYY.MM" and
outputs the day of the first day in that month.
The program may run as follows:
Input a month (YYYY.MM) -- 2014.11
The first day of 2014.11 is Saturday.
Input a month (YYYY.MM) -- 2014.1
The first day of 2014.1 is Wednesday.
Input a month (YYYY.MM) -- 2014.12
The first day of 2014.12 is Monday.