还要注意 break 与 default,下面的样例没有此二点
输入年月日,判断这一天是这一年的第几天。 #include<stdio.h> int main() { int year,month,date,leap,days=0; scanf("%4d%2d%2d",&year,&month,&date); leap=(year%4==0&&year%100!=0||year%400==0); switch(month) { case 12:days+=30; case 11:days+=31; case 10:days+=30; case 9:days+=31; case 8:days+=31; case 7:days+=30; case 6:days+=31; case 5:days+=30; case 4:days+=31; case 3:days+=28+leap; case 2:days+=31; case 1:days+=date;break; } printf("%4d年%2d月%2d日是这一年的第%d天。 ",year,month,date,days); }