计算一年中的一天是星期几

#include <stdio.h>

char * name[]= {"Monday","Tuesday","Wednesday","Thursday","Friday","Saturday","Sunday"};

int main()
{
        int d,m,y,a;
        printf("Day: ");    scanf("%d",&d);
        printf("Month: ");    scanf("%d",&m);
        printf("Year: ");    scanf("%d",&y);
         if( m == 1 || m == 2 )
    {       
         m += 12;
        if( y> 0 )      y--;
        else      y = 4;
    }
        printf ("it's a %s\n ",name[(( d + 2*m + 3*(m+1)/5 + y + y/4 ) %7)]);
        return 0;
}

 

posted on 2012-03-24 14:15  _Clarence  阅读(78)  评论(0编辑  收藏

导航

统计