Different months have different numbers of days, and there is the problem of leap years.
Given the complications involved, it's quite surprising how short an expression will do. Note that the expression may modify the value of y , so it's best to use it in a subroutine. Here is a brief explanation, condensed from my paper in Journal of Recrational Mathematics , Vol. It's relatively easy to see that this is equivalent to the C version. The next term, d , simply adjust the sum based on the day of the month.