若有定义:float x=1.5;int a=1,b=3,c=2;则正确的switch语句是______。A.switch (x) {case 1.

题目

若有定义:float x=1.5;int a=1,b=3,c=2;则正确的switch语句是______。

A.switch (x) {case 1.0: printf("*\n"); case 2.0: printf("**\n");}

B.switch ( (int)x); {case 1: printf("*\n"); case2: printf("**\n");}

C.switch (a+b) {case 1:printf("*\n"); case 2+1: printf("**\n");}

D.switch (a+b)) {case 1: pfintf("*\n")}; case c: printf("**\n"));}

如果没有搜索结果或未解决您的问题,请直接 联系老师 获取答案。
相似问题和答案

第1题:

若有定义:float x=1.5; int a=1, b=3, c=2;,则正确的switch语句是()。

A.switch(x) { case 1.0: printf("*"); case 2.0: printf("**"); }

B.switch((int)x); { case 1: printf("*"); case 2: printf("**"); }

C.switch(a+b) { case 1: printf("*"); case 1+2: printf("**"); }

D.switch(a+b) { case 1: printf("*"); case c: printf("**"); }


C

第2题:

若有定义: float x=1.5; int a=1,b=3,c=2; 则正确的switch语句是()。

A.switch(a+b) { case 1: printf("*n"); case 2+1: printf("**n"); }

B.switch((int)x); { case 1: printf("*n"); case 2: printf("**n"); }

C.switch(x) { case 1.0: printf("*n"); case 2.0: printf("**n"); }

D.switch(a+b) { case 1: printf("*n"); case c: printf("**n"); }


D

第3题:

若有定义:float x=1.5;int a=1,b=3,c=2;则正确的 switch 语句是

A.switch(x) { case1 .0:printf("* n"); Case2.0:printf(“**n”);}

B.switch((int)x); {case 1:printf(“*n”); case 2:printf(“**n”);}

C.switch(a+b) {case 1:printf(“*n”); case 2+1:printf(“**n”);}

D.switch(a+b) {case 1:printf(“*n”); Case c:printf(“**n”);}


C

第4题:

1.若有定义:“float x=1.5; int a=1,b=3,c=2;”,则正确的switch语句是 。

A.switch (x) {case 1.0:printf("*n"); case 2.0:printf("**n");}

B.switch ((int)x) ; {case 1:printf("*n"); case 2:printf("**n");}

C.switch (a+b) {case1:printf(**n); case c:printf(**n);}

D.switch (a+b) {case 1:printf("*n"); case 2+1:printf("**n");}


B

第5题:

若有定义:float x=1.5;int a=1,b=3,c=2;则正确的switch 语句是( )。

A.switch(x) {case 1.0: printf("*\n"); case 2.0: printf("**\n");}

B.switch((int)x); { case 1: printf("*\n"); case 2: printf("**\n");}

C.switch(a +b) { case 1: printf("*\n"); case 2+1: printf("**\n");}

D.switch(a+ b) { case 1: printf("*\n"); case c: printf("**\n");}


正确答案:C
解析:switch后的括号中只能是整型或字符型表达式,选项A中使用的是浮点型变量x,故不正确。选项B在switch的括号后面多了一个分号,故也不正确。switch的case标号后只能是常量或常量表达式,而不能是变量,所以选项D也不正确。故应该选择C。

第6题:

若有定义float x=1.5;int a=1,b=3,c=2;,则正确的switch语句是

A.switch(x) {case 1.0:printf("*\n"); case 2.0:printf("**\n");}

B.switch((int)x); {case1:printf("*\n"); case 2:printf("**\n");}

C.switch(a+b) {case 1:printf("*\n"); case 2+1:printf("**\n");}

D.switch(a+b) {case 1:printf("*\n"); case c:printf("**\n");}


正确答案:C
解析:C语言中,switch语句专用于实现多分支结构程序,其特点是各分支清晰且直观。switch后面括号中可以是任何表达式,取其整数部分与各常量表达式进行比较。常量表达式中不能出现变量,且类型必须是整型、字符型或枚举型,各常量表达式各不相同。

第7题:

若有定义:float x=1.5;int a=1,b=3,c=2;则正确的switch语句是( )。

A.switch(x)

B.switch((int)x); {case 1.0:printf("*\n"); {case 1:printf("*\n"); case 2.0:printf("**\n");} case 2:printf("**\n");}

C.switch(a+B)

D.switch(a+B){case 1;printf("*\n"); {case 1:printf("*\n"); case 2+1:printf("**\n");} case c:printf("**\n");)


正确答案:C

第8题:

若有定义:float x=1.5;int a=1,b=3,c=2;则正确的switch语句是( )。

A.switch(x) {case 1.0:printf("*\n"); case 2.0:printf("**\n");}

B.switch((int)x); {case 1:printf("*\n"); case 2:printf("**\n");}

C.switch(a+B){case 1:printf("*\n"); case 2+1:printf("**\n");}

D.switch(a+B){case 1:printf("*\n"); case c:printf("**\n");)


正确答案:C

第9题:

若有定义:float x=1.5;int a=1,b=3,c=2;,则正确的switch语句是

A.switch(x) {case 1.0:printf("*\n"); case 2.0:printf("**\n");}

B.switch((int)x); {case 1:printf("*\n"); case 2:printf("**\n");}

C.switch(a+B) {case 1:printf("*\n"); case 2+1:printf("**\n");}

D.switch(a+B) {case 1:printf("*\n"); case c:printf("**\n");}


正确答案:C
解析: C语言中,switch语句专用于实现多分支结构程序,其特点是各分支清晰而直观。switch后面括号中可以是任何表达式,取其整数部分与各常量表达式进行比较。常量表达式中不能出现变量,且类型必须是整型、字符型或枚举型,各常量表达式各不相同。