switch-case嵌套if-else问题
在case后 嵌套if-else,并不执行if-else的条件判断,直接执行if之后else之前的语句,这是怎么回事?(可以正常运行,但运行结果有误。)
下面是程序
#include<stdio.h>
int main()
{
int d,m,y,w,a;
scanf("%d%d%d",&y,&m,&d);
a=m;
if(m==1||m==2)
m=m+12;
w=(d+2*m+3*(m+1)/5+y+y/4-y/100+y/400+1)%7;
if(w==7)
w=0;
if(a<0||a>12)
printf("month is error.");
else
{
switch(a)
{
case 1:{if(1<=d<=31)printf("1");else printf("day is error.");
break;
}
case 2:{if(1<=d<=29){if(0<d<30&&((y%4==0&&y%100!=0)||y%400==0))printf("2");else
{if(d==29)
printf("day is error.");
else
printf("2");
}
}
else
printf("month is error.");
break;
}
case 3:{if(1<=d<=31)printf("%d",w);else printf("day is error.");break;}
case 4:{if(1<=d<31)printf("%d",w);else printf("day is error.");break;}
case 5:{if(1<=d<=31)printf("%d",w);else printf("day is error.");break;}
case 6:{if(1<=d<31)printf("%d",w);else printf("day is error.");break;}
case 7:{if(1<=d<=31)printf("%d",w);else printf("day is error.");break;}
case 8:{if(1<=d<=31)printf("%d",w);else printf("day is error.");break;}
case 9:{if(1<=d<31)printf("%d",w);else printf("day is error.");break;}
case 10:{if(1<=d<=31)printf("%d",w);else printf("day is error.");break;}
case 11:{if(1<=d<31)printf("%d",w);else printf("day is error.");break;}
case 12:{if(1<=d<=31)printf("%d",w);else printf("day is error.");break;}/*错误在这里,可以通过调试,正常运行,但运行结果有误。*/
}
}
}