举一反三
- 若有定义语句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: 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;}
- 以下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; }
- 下面程序段的输出结果是______。 int n= int n='c'; switch(n++) {default: printf("error"); break; case 'a': case 'A': case 'b': case 'B': printf("good"); break; case 'c': case 'C': printf("pass"); case 'd': case 'D': printf("warn"); }
- 当month 等于6时,下面代码的输出结果是()。 int days = 0; switch (month) { case 2: days = 28; break; case 4: case 6: case 9: case 11: days = 30; break; default: days = 31; break; }
内容
- 0
中国大学MOOC: 以下代码sum的值是( )int sum = 0;int i = 4;switch(i%3) {case 0: sum = sum+i;break;case 1: sum = sum+i+1;case 2: sum = sum+i+2;break;}
- 1
变量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}
- 2
如果month=4,下面代码的输出结果是( ) int days=0; switch(month) { case 2: days=28; break; case 4: case 6: case 9: case 11: days=30; break; default: days=31; break; } Console.WriteLine(days);
- 3
中国大学MOOC: 如下代码片段的输出是什么? int a = 1, b = 0; switch (a) { case 1: switch (b) { case 0: printf (**0**); break; case 1: printf (**1**); break; } case 2: printf (**2**); break; }
- 4
若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; }