Programming Pearls: Chatper3 Problem4 [Dates Caculation]

The first program

The second program
Lesson Learned: 将 daysInMonth[]的内容拷贝到 leapYearDaysInMonth[]的时候忘记将闰二月改为29天... 看来每次写完一条语句都应该verify一下。这个看似浪费时间,却真正能够减少debugging的大量时间呀

The third program
Input: 1981 8
Output: 
    Sunday     Monday    Tuesday  Wednesday   Thursday     Friday   Saturday
                                                                                                   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

Lesson Learned: 居然犯下如此低级的C语言数组下标错误,将 pDaysInMonth[month-1]写成了pDaysInMonth[month]。哎,人类语言从1为下标,而C语言从0开始下标。要将此作为我的一个Programming Alarm。。。

你可能感兴趣的:(programming)