各位大哥 帮忙解释下这个程序[tk01]
#include <stdio.h>int DayOfWeek(int y, int m, int d)
{
static int t[] = {0, 3, 2, 5, 0, 3, 5, 1, 4, 6, 2, 4};
y -= m < 3;
return (y + y/4 - y/100 + y/400 + t[m-1] + d) % 7;
}
int IsLeapYear(int year)
{
return year % 4 == 0 && (year % 100 != 0 || year % 400 == 0);
}
int DayOfMonth(int y,int m)
{
if (m==2) return 28 + IsLeapYear(y);
return 30 + ((m%2)==(m<8));
}
int main()
{
int y,m,d,w,mc;
while (scanf("%d %d",&y,&m)==2 && y>=0 && m>0 && m<=12)
{
printf(" S M T W T F S\n");
if (w=DayOfWeek(y,m,1))
{
mc=DayOfMonth(y,(m+10)%12+1);
for (d=mc-w+1;d<=mc;d++)
printf("%2d ",d);
}
mc=DayOfMonth(y,m);
for (d=1;d<=mc;d++)
printf("%2d%c",d,(w=(w+1)%7)?' ':'\n');
if (w) for (d=1;w<7;w++,d++)printf("%2d ",d);
putchar('\n');
}
return 0;
}
这个的确是短小精悍 但是我看不懂吖