天数与月份之间的相互转换

#include
void  MonthDay(int year, int yearDay, int *pMonth, int *pDay);
int 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 main()     
{
        int year, month, day, yearDay;
        printf("Please enter year, yearDay:");
        scanf("%d,%d", &year, &yearDay);
        MonthDay(year,yearDay,&month,&day);
        printf("month=%d,day=%d\n",month,day); 
        return 0;  
}
    /* 函数功能:对给定的某一年的第几天,计算它是这一年的第几月第几日 */
void  MonthDay(int year, int yearDay, int *pMonth, int *pDay)
    {  
        int i,leap;
        leap=((year%4==0)&&(year%100!=0))||(year%400==0);  
        for (i=1; yearDay>dayTab[leap][i]; i++)
        {
            yearDay=yearDay-dayTab[leap][i];
        }
        *pMonth=i;   /* 将计算出的月份值赋值给pMonth所指向的变量 */
        *pDay = yearDay;   /* 将计算出的日号赋值给pDay所指向的变量 */
    }

天数与月份之间的相互转换_第1张图片

#include
void  MonthDay(int year, int yearDay, int *pMonth, int *pDay);
int 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 main()     
{
        int year, month, day, yearDay;
        printf("Please enter year, yearDay:");
        scanf("%d,%d", &year, &yearDay);
        MonthDay(year,yearDay,&month,&day);
        printf("month=%d,day=%d\n",month,day); 
        return 0;  
}
    /* 函数功能:对给定的某一年的第几天,计算它是这一年的第几月第几日 */
void  MonthDay(int year, int yearDay, int *pMonth, int *pDay)
    {  
        int i,leap;
        leap=((year%4==0)&&(year%100!=0))||(year%400==0);  
        for (i=1; yearDay>dayTab[leap][i]; i++)
        {
            yearDay=yearDay-dayTab[leap][i];
        }
        *pMonth=i;   /* 将计算出的月份值赋值给pMonth所指向的变量 */
        *pDay = yearDay;   /* 将计算出的日号赋值给pDay所指向的变量 */
    }

天数与月份之间的相互转换_第2张图片

你可能感兴趣的:(天数与月份之间的相互转换)