求助,确定感恩节
感恩节是每年11月的第四个星期四,请输入年份,计算该年11月的哪一天是感恩节。
2016-11-24 13:05
程序代码:#include <stdio.h>
#include <time.h>
int foo( int year )
{
struct tm a = { 0,0,0, 1,11-1,year-1900, 0,0,0 };
time_t b = mktime( &a );
if( b == -1 )
return 0;
struct tm c = *localtime( &b );
return (11-c.tm_wday)%7 + 22;
}
int main( void )
{
printf( "%d\n", foo(2015) ); // 26
printf( "%d\n", foo(2016) ); // 24
printf( "%d\n", foo(2017) ); // 23
}
2016-11-24 16:30