开始将搜狐博客里的文章搬到CSDN了,
int odd(int x)
{
return x%2;
}
int main()
{
int x=10;
switch (x)
default:
if (odd(x))
{
case 1: printf("1 \n");break;
case 3: printf("3 \n");break;
case 5: printf("5 \n");break;
case 7: case 9:
printf("odd\n");
}
else
case 2: case 4: case 6: case 8: case 10:
printf("even\n");
}
当x<=10时执行相应步骤,但x>10的奇数时却只执行case1, Why?
思考:dafault中如果能找到与switch(x)相符合的X,则执行相应语句;若不能则“顺序执行”?
转自 http://jluhlh.blog.sohu.com/136878685.html