![在这里插入图片描述](https://img-blog.csdnimg.cn/20210309230223472.png?x-oss-process=image/watermark,type_ZmFuZ3poZW5naGVpdGk,shadow_10,text_aHR0cHM6Ly9ibG9nLmNzZG4ubmV0L3dlaXhpbl81MjIwMTk5Ng==,size_16,color_FFFFFF,t_70
输入样例
2000 61
输出样例
2000 3 1
# include <stdio.h>
void month_day ( int year, int yearday, int * pmonth, int * pday);
int main (void)
{
int day, month, year, yearday; /* 定义代表日、月、年和天数的变量*/
scanf ("%d%d", &year, &yearday );
month_day (year, yearday, &month, &day );/* 调用计算月、日函数 */
printf ("%d %d %d\n", year, month, day );
return 0;
}
void month_day ( int year, int yearday, int * pmonth, int * pday){
int k,leap;
int tab[2][100]={
{0,31,28,31,30,31,30,31,31,31,30,31,30},//78月都是31天呀
{0,31,29,31,30,31,30,31,31,31,30,31,30},
};//别忘了分号!
leap=((year%4==0&&year%100!=0)||year%400==0);
for(k=1;yearday>tab[leap][k];k++){//k从1开始因为0的位置对应数为0
yearday-=tab[leap][k];//减的是每个月的总天数
}
*pmonth=k;
*pday=yearday;//剩下的不足一个月的天数
}