1. 以下程序的输出结果是________。int main(void){ int x,y; x=y=2; switch(x){ case 1: y++; case 2: y=y+2; case 3: y=y+3 ;break ; default:y=y+4 ; break;} printf("%d",y) ; return 0 ;} A. 3 B. 4 C. 11 D. 7
A: 3
B: 4
C: 11
D: 7
A: 3
B: 4
C: 11
D: 7
举一反三
- int main()执行结果是(){int x=2,y=1; switch(x) { case 1: y=x ; break; case 2: y=-x ; case 3: y=x*3 ; break; case 4: y=4*x; } printf(“%d\n”,y);}
- 1、main(){ int x=2,y;switch(x){ case 1: y=x ; break;case 2: y=-x ;case 3: y=x*3 ; break;case 4: y=4*x;}printf(“%d\n”,y);}程序运行结果:__________________
- 下面代码的执行后y的值是多少?int x=1,y;switch(x){case 1:y=1;case 2:y=2;case 3:y=3;break;default:y=4;}
- 下面程序段执行后的输出结果是( )。int main(){int x=3,y=6;switch(x) {case 1:y++;case 2:++y;break;default:y++;}printf("%d\n", y);return 0;} A: 6 B: 7 C: 8 D: 9
- 以下switch语句结构哪一个是正确的?( ) A: int a=1,b=0,c1,c2,x,y;switch (a*a+b*b) { case 3: case 1: y=a+b; break; case 3: y=b-a; break;} B: int a=1,b=0,c1,c2,x,y;switch a ( ) { case c1: y=a-b; break; case c2: x=a*b; break; default:x=a+b;} C: int a=1,b=0,c1,c2,x,y;switch (a*a+b*b) { default:y=a*b;break; case 3: x=a+b; break; case 10: case 11:y=a-b; break;} D: int a=1,b=0,c1,c2,x,y;switch (a+b); { case 1: y=a+b; break; case 0: y=a-b; break; }