题目内容

以下关于switch语句和break语句的描述中,只有()是正确的

A. 在switch语句中必须使用break语句
B. 在switch语句中,可以根据需要使用或不使用break语句。
C. break语句在switch语句中没有作用。
D. break语句是switch语句的一部分。

查看答案
更多问题

下列程序段的输出结果是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");}

A. pass
B. wam
C. passwarn
D. error

若有定义: float w;int a,b;则合法的switch语句是()。

A. .switch(a){case 1.0:printf("*\n");case 2.0:printf("**\n");}
B. switch(a){case 1 printf("*\n");case 2 printf("**\n");}
C. switch(w){case 1:printf("*\n");default:printf("\n");case 1+2:printf("**\n");}
D. switch(a+b){ case 1:printf("*\n");case 2:printf("**\n");default:printf("\n");}

以下程序完成简单的“+、- 、*、/”运算,请完善程序,保证运行正确。int main(){float a,b;double r;char c;scanf("%f%c%f",&a,&c,&b);switch(){case '+': r=a+b;break;case '-': r=a-b;break;case '*': r=a*b;break;case '/': if(!b) r=a/b;}if()printf("error\n");elseprintf("%.2f %c %.2f = %.2lf\n",a,c,b,r);return 0;}

阅读下列程序段,写出运行结果( )。int a=12,b=21,m=0;switch(a%3){case 0:m++;switch(b%2){default :m++;case 0:m++;break;}}

答案查题题库