根据年月日计算今天是一年中的第几天

根据年月日计算今天是一年中的第几天


static char daytab[2][13]= {  
    {0, 31, 28, 31, 30, 31, 30, 31, 31, 30, 31, 30, 31},  
    {0, 31, 29, 31, 30, 31, 30, 31, 31, 30, 31, 30, 31}  
};


int day_of_year(int year, int month, int day){  
    int i, leap;  
  
    leap = year % 4 == 0 && year % 100 != 0 || year % 400 == 0;  
  
    for (i = 1; i < month ; i++) {  
        day += daytab[leap][i];  
    }  
    return day;  
}

你可能感兴趣的:(_00_C语言)