若有定义: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");}
查看答案
下面程序段的输出结果是______。int n='c';switch(n++) // n先用,后自增(n=’c’)。{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. passwarn
B. passerror
C. goodpasswarn
D. pass
下述程序的输出结果是_______。#inlude int main(){ int x=1,y=0,a=0,b=0;switch(x){ case 1: switch(y){ case 0: a++; break;case 1: b++;break; }case 2: a++;b++;break;case 3: a++;b++;}printf("\na=%d,b=%d",a,b);return 0; }
A. a=1,b=0
B. a=2,b=1
C. a=1,b=1
D. a=2,b=2
以下程序运行后的输出结果是_______。#inlude int main(){ int a=15,b=21,m=0;switch(a%3) //15%3=0{ case 0: m++; break; // 执行后,退出第一层。case 1: m++;switch(b%2) //第二层,未执行{ default: m++;case 0: m++; break; }}printf("%d\n",m);return 0; }
A. 1
B. 2
C. 3
D. 4
在执行下述程序时,若从键盘输入字母H,则输出结果是_______。#inlude int main(){ char ch;ch=getchar();switch(ch){ case 'H':printf("Hello! \n");case 'G':printf("Good morning! \n");default:printf("Bye_Bye! \n"); }return 0; }
A. Hello!
B. Hello! Good morning!
C. Hello!Good morning!Bye_Bye!
D. Hello!Bye_Bye!