首页 > 代码库 > 输入年份和天数计算出几月几号

输入年份和天数计算出几月几号

//转换函数如下,其中通过指针同时向主函数传回月份和天数

void month_day(int year, int yearday, int *month, int *day){

//k月份,leap判断是否闰年(0非闰年1闰年)
int k, leap;
int tab[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 },
};
leap = (year % 4 == 0 && year % 100 != 0) || year % 400 == 0;
for (k = 1; yearday>tab[leap][k]; k++){
yearday = yearday - tab[leap][k];
}
*day = yearday;
*month = k;
}