- On Unix, there is a command "cal" to print out the calendar of a
specific month. For example, "cal 1 2014" prints out the calendar of
January 2014.
January 2014
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
- Develop a function cal(month_days, n) to do the
following tasks:
- Suppose the 1st day in a month is the nth day in a week (assume
Sunday is the 0th, Monday is the 1st, Wednesday is the 3rd, and so
on.)
- Print 3*n spaces.
- Using a for-loop to print 1, 2, 3, ..., month_days (the
possible values of month_days are 28, 29, 30, 31,
depending on which month it is). If the date printed out is
Saturday, output a newline (\n) character.
- For example, cal(31, 0) shows the following
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
while cal(29, 5) shows the following:
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
- Since we know how to calculate what day the first day in a month
will be, you can directly import that function to calculate the day
in a week D, then invoke the function cal(month_days, D).
- You may also output the name of the month, and also weekdays, to
make it looks more informative.
The output may look like this:
Input a month (YYYY.MM) -- 2014.11
November 2014
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
|
|