变量a,b,x已经通过语句int a=1, b=2;double x=4;声明,则下列选项中没有错误的是
A: switch(x%2){case 1:break}
B: switch(x){case 1:break}
C: switch((int)x%2){case 1:break}
D: switch((a/2.0){case 1:break}
A: switch(x%2){case 1:break}
B: switch(x){case 1:break}
C: switch((int)x%2){case 1:break}
D: switch((a/2.0){case 1:break}
举一反三
- 若有定义语句int a, b;double x;则下列选项中正确的是( ). A: switch(x%2) { case 0: a++; break; case 1: b++; break; default : a++; b++; } B: switch((int)x/2.0) { case 1: b++; break; case 0: a++; break; default : a++; b++; } C: switch((int)x%2) { case 0: a++; break; case 1: b++; break; default : a++; b++; } D: switch((int)(x)%2) { case 0.0: a++; break; case 1.0: b++; break; default : a++; b++; }
- 若a为整型变量,b为字符型变量,则以下正确的switch语句是 A: switch((int)x/10){ case 1:a++;break;case 2:b++;break;case 3:c++;break;} B: switch(b){ case ‘\042’;x=a/b;break;case ‘6’;x=a*b;break;case ‘\010’;x=a+c;break;} C: switch((int)x/10);{ case 0:a++;break;default:b++;break;case 3+1:c++;break;case 3:d++;break;} D: switch(a/100+10){ case2 :x=a/b;break; case6 :x=a*b;break;case8 :x=a+c;break;case10 :x=a-c;break; }
- 以下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; }
- 下述程序段中,无语法错误的是: A: int a=2,b=0; switch(a){ case b+1:a--;break; case b=5: a+=10;break;} B: char x=‘A’,y; switch(x){ case ‘A’:y++;break; case -1: y=5; } C: int a,b=5; switch(b) { case b>;0: a=1;break; case b==0: a=0;break; } D: E: define M 10 int a=1,b; switch(a) {case M-9:b+=5;break; case 1: b=1;break;}
- 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);}