//转换函数如下,其中通过指针同时向主函数传回月份和天数
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;
}
时间: 2024-10-14 10:05:10