例:输入格式:2000 61
输出格式:2000-3-1 即2000年的第61天是3月1日
//使用指针作为函数参数返回多个函数值
#include
void month_day(int year,int yearday,int *pmonth,int *pday){
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-=tab[leap][k];
*pmonth=k;
*pday=yearday;
}
int main(){
int day,month,yearday,year; //定义代表日、月、年和天数的变量
printf("input year and yearday:");
scanf("%d%d",&year,&yearday);
month_day(year,yearday,&month,&day);
printf("%d-%d-%d",year,month,day);
return 0;
}