这个问题很简单,以下是我写的源代码,调试通过,你可以试试,写的很基础,应该能看懂,不懂追问!
#include
#include
void
Monthday(int
year,int
yearDay,int
*pMonth,int
*pDay)
{
int
dec
;
if((year%4
==
0
&&
year
%100
!=
0)
||
(year
%
400
==
0)
)//若是闰年
{
dec
=
0;
}
else
dec
=
1;
if(yearDay
>=
1
&&
yearDay
<=
31
)
{
*pMonth
=
1;
*pDay
=
yearDay;
}
else
if(yearDay
>=
32
&&
yearDay
<=
60
-
dec)
{
*pMonth
=
2;
*pDay
=
yearDay
-
31;
}
else
if(yearDay
>=
61-
dec
&&
yearDay
<=
91-
dec
)
{
*pMonth
=
3;
*pDay
=
yearDay
-
60-
dec;
}
else
if(yearDay
>=
92-
dec
&&
yearDay
<=
121
-
dec)
{
*pMonth
=
4;
*pDay
=
yearDay
-
91-
dec;
}
else
if(yearDay
>=
122-
dec
&&
yearDay
<=
152-
dec
)
{
*pMonth
=
5;
*pDay
=
yearDay
-
121-
dec;
}
else
if(yearDay
>=
153-
dec
&&
yearDay
<=
183-
dec
)
{
*pMonth
=
6;
*pDay
=
yearDay
-
152-
dec;
}
else
if(yearDay
>=
184-
dec
&&
yearDay
<=
214
-
dec)
{
*pMonth
=
7;
*pDay
=
yearDay
-
183-
dec;
}
else
if(yearDay
>=
215-
dec
&&
yearDay
<=
245
-
dec)
{
*pMonth
=
8;
*pDay
=
yearDay
-
214-
dec;
}
else
if(yearDay
>=
246-
dec
&&
yearDay
<=
275-
dec
)
{
*pMonth
=
9;
*pDay
=
yearDay
-
245-
dec;
}
else
if(yearDay
>=
276-
dec
&&
yearDay
<=
306-
dec
)
{
*pMonth
=
10;
*pDay
=
yearDay
-
275-
dec;
}
else
if(yearDay
>=
307-
dec
&&
yearDay
<=
336-
dec
)
{
*pMonth
=
11;
*pDay
=
yearDay
-
306-
dec;
}
else
if(yearDay
>=
337-
dec
&&
yearDay
<=
367-
dec
)
{
*pMonth
=
12;
*pDay
=
yearDay
-
336-
dec;
}
}
int
main()
{
int
year,yearDay;
int
*pMonth
=
new
int(0);
int
*pDay
=
new
int(0);
printf("请输入
年,日:\n");
scanf("%d,%d",&year,&yearDay);
Monthday(year,yearDay,pMonth,pDay);
printf("month
=
%d
,
day
=
%d\n",*pMonth,*pDay);
return
0;
}