如果月份是一月的某天,怎么设置条件,我发现大多数人的答案只适用于大于2月份的情况下
#include <stdio.h>
int main()
{
int year = 2020;
int month = 1;
int day = 31;
int sum;
switch(month)
{
case 1: sum=day; break;
case 2: sum=31+day; break;
case 3: sum=31+28+day; break;
case 4: sum=31+28+31+day; break;
case 5: sum=31+28+31+30+day; break;
case 6: sum=31+28+31+30+31+day; break;
case 7: sum=31+28+31+30+31+30+day; break;
case 8: sum=31+28+31+30+31+30+31+day; break;
case 9: sum=31+28+31+30+31+30+31+31+day; break;
case 10:sum=31+28+31+30+31+30+31+31+30+day; break;
case 11:sum=31+28+31+30+31+30+31+31+30+31+day; break;
case 12:sum=31+28+31+30+31+30+31+31+30+31+30+day; break;
default:printf("一年当中只有12个月份哦"); break;
}
if(year%400==0||year%4==0&&year%100!=0)
{
sum++;
printf("%d年是闰年\n",year);
printf("%d年%d月%d日是该年的第%d天",year,month,day,sum);
}
else
{
printf("%d年是平年\n",year);
printf("%d年%d月%d日是该年的第%d天",year,month,day,sum);
}
return 0;
}