#include<stdio.h>
int main()
{
//给出一个年月日,判断是这一年的第几天
//闰年算法:能被4整除且不能被100整除,或者能被400整除
int year, month, day;
int year1, month1, day1;
scanf_s("%d%d%d", &year, &month, &day);
int temp1 = 0;//默认平年
int temp2 = 0;
year1 = year, month1 = month, day1 = day;
if (month > 1&&(year % 4 == 0 && year / 100 != 0 || year / 400 == 0))
{
day += 1;
}
while (month > 1)
{
switch (month)
{
case 1:
case 3:
case 5:
case 7:
case 8:
case 10:
case 12:
temp2 = 31;
break;
case 2:
temp2 = 28;
break;
case 4:
case 6:
case 9:
case 11:
temp2 = 30;
break;
}
month--;
day += temp2;
}
/*for (int i = month; i > 1; i--)
{
switch (month)
{
case 1:
case 3:
case 5:
case 7:
case 8:
case 10:
case 12:
temp2 = 31;
break;
case 2:
temp2 = 29;
break;
case 4:
case 6:
case 9:
case 11:
temp2 = 30;
break;
}
month--;
day += temp2;
}*/
printf("%d年%d月%d日是这一年的第%d天\n", year1,month1, day1, day);
}
10-18
2171
![](https://csdnimg.cn/release/blogv2/dist/pc/img/readCountWhite.png)
12-07
773
![](https://csdnimg.cn/release/blogv2/dist/pc/img/readCountWhite.png)