#include <stdio.h>
int main()
{
int year = 2008;
int month = 8;
int day = 8;
int sum;
switch(month)
{
case(1):sum=day;break;
case(2):sum=day+31;break;
case(3):sum=day+31+28;break;
case(4):sum=day+31+28+31;break;
case(5):sum=day+31+28+31+30;break;
case(6):sum=day+31+28+31+30+31;break;
case(7):sum=day+31+28+31+30+31+30;break;
case(8):sum=day+31+28+31+30+31+30+31;break;
case(9):sum=day+31+28+31+30+31+30+31+31;break;
}
if(year%4==0&&year%100!=0||year%400==0)
{
sum+=1;
}
else
{
sum=sum+0;
}
printf("是该年的第%d天",sum);
return 0;
}
对照解析看,少个闰年的输出,而且少了default只能有十二个月特定条件